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

static int coveig (int n, float *covmat, float *eigval, float *eigvec)
 This file is a part of util.h, To use this file's functions, you should include "util.h" NEVER directly include this file.
static Dict coveig_for_py (int ncov, const vector< float > &covmatpy)
 same function than Util::coveig but wrapped to use directly in python code
static void WTF (EMData *PROJ, vector< float > SS, float SNR, int K)
static void WTM (EMData *PROJ, vector< float > SS, int DIAMETER, int NUMP)
static Dict CANG (float PHI, float THETA, float PSI)
static void BPCQ (EMData *B, EMData *CUBE, vector< float > DM)
static vector< float > infomask (EMData *Vol, EMData *mask, bool)
static void colreverse (float *beg, float *end, int nx)
static void slicereverse (float *beg, float *end, int nx, int ny)
static void cyclicshift (EMData *image, Dict params)
 Performs inplace integer cyclic shift as specified by the "dx","dy","dz" parameters on a 3d volume.
static Dict im_diff (EMData *V1, EMData *V2, EMData *mask=0)
static EMDataTwoDTestFunc (int Size, float p, float q, float a, float b, int flag=0, float alphaDeg=0)
 Creates a Two D Test Pattern.
static void spline_mat (float *x, float *y, int n, float *xq, float *yq, int m)
 Given a tabulated function y of x (n unordered points), and Given the values of the m values xq to be interpolated This routine returns the interpolated array yq, PRB This function is called by splint.
static void spline (float *x, float *y, int n, float yp1, float ypn, float *y2)
 Given a tabulated function y of x (unordered), and Given the values of the first derivatives at the end points This routine returns an array y2, that contains the second derivatives of the function at the tabulated points.
static void splint (float *xa, float *ya, float *y2a, int n, float *xq, float *yq, int m)
 Given the arrays xa(ordered, ya of length n, which tabulate a function and given the array y2a which is the output of spline and an unordered array xq, this routine returns a cubic-spline interpolated array yq.
static void Radialize (int *PermMatTr, float *kValsSorted, float *weightofkvalsSorted, int Size, int *SizeReturned)
 list the sorted lengths of the integer lattice sites of a square sided image of size Size.
static vector< float > even_angles (float delta, float t1=0, float t2=90, float p1=0, float p2=359.999)
 Compute a vector containing quasi-evenly spaced Euler angles.
static float quadri (float x, float y, int nx, int ny, float *image)
 Quadratic interpolation (2D).
static float quadri_background (float x, float y, int nx, int ny, float *image, int xnew, int ynew)
 Quadratic interpolation (2D).
static float get_pixel_conv_new (int nx, int ny, int nz, float delx, float dely, float delz, float *data, Util::KaiserBessel &kb)
static float get_pixel_conv_new_background (int nx, int ny, int nz, float delx, float dely, float delz, float *data, Util::KaiserBessel &kb, int xnew, int ynew)
static std::complex< float > extractpoint2 (int nx, int ny, float nuxnew, float nuynew, EMData *fimage, Util::KaiserBessel &kb)
static float bilinear (float xold, float yold, int nsam, int nrow, float *xim)
static float triquad (float r, float s, float t, float *fdata)
 Quadratic interpolation (3D).
static EMDataPolar2D (EMData *image, vector< int > numr, string mode)
static EMDataPolar2Dm (EMData *image, float cns2, float cnr2, vector< int > numr, string cmode)
static void alrl_ms (float *xim, int nsam, int nrow, float cns2, float cnr2, int *numr, float *circ, int lcirc, int nring, char mode)
static EMDataPolar2Dmi (EMData *image, float cns2, float cnr2, vector< int > numr, string cmode, Util::KaiserBessel &kb)
static void fftr_q (float *xcmplx, int nv)
static void fftr_d (double *xcmplx, int nv)
static void fftc_q (float *br, float *bi, int ln, int ks)
static void fftc_d (double *br, double *bi, int ln, int ks)
static void Frngs (EMData *circ, vector< int > numr)
 This function conducts the Single Precision Fourier Transform for a set of rings.
static void Normalize_ring (EMData *ring, const vector< int > &numr)
static void Frngs_inv (EMData *circ, vector< int > numr)
 This function conducts the Single Precision Inverse Fourier Transform for a set of rings.
static Dict Crosrng_e (EMData *circ1, EMData *circ2, vector< int > numr, int neg)
static Dict Crosrng_ew (EMData *circ1, EMData *circ2, vector< int > numr, vector< float > w, int neg)
static Dict Crosrng_ms (EMData *circ1, EMData *circ2, vector< int > numr)
static Dict Crosrng_ms_delta (EMData *circ1, EMData *circ2, vector< int > numr, float delta_start, float delta)
static Dict Crosrng_sm_psi (EMData *circ1, EMData *circ2, vector< int > numr, float psi, int flag)
 checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights!
static Dict Crosrng_psi_0_180 (EMData *circ1, EMData *circ2, vector< int > numr, float psi_max)
 checks both straight & mirrored positions Find only positions within +/-pis_max of 0 and 180 (for helcal use) input - fourier transforms of rings! circ1 already multiplied by weights!
static Dict Crosrng_ns (EMData *circ1, EMData *circ2, vector< int > numr)
static 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
static void Crosrng_msg_vec (EMData *circ1, EMData *circ2, vector< int > numr, float *q, float *t)
 checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
static EMDataCrosrng_msg_s (EMData *circ1, EMData *circ2, vector< int > numr)
 This program is half of the Crosrng_msg.
static EMDataCrosrng_msg_m (EMData *circ1, EMData *circ2, vector< int > numr)
 This program is half of the Crosrng_msg.
static vector< float > Crosrng_msg_vec_p (EMData *circ1, EMData *circ2, vector< int > numr)
static void prb1d (double *b, int npoint, float *pos)
static void update_fav (EMData *ave, EMData *dat, float tot, int mirror, vector< int > numr)
static void sub_fav (EMData *ave, EMData *dat, float tot, int mirror, vector< int > numr)
static float ener (EMData *ave, vector< int > numr)
static float ener_tot (const vector< EMData * > &data, vector< int > numr, vector< float > tot)
static Dict min_dist_real (EMData *image, const vector< EMData * > &data)
 k-means helper
static Dict min_dist_four (EMData *image, const vector< EMData * > &data)
 helper function for k-means
static int k_means_cont_table_ (int *group1, int *group2, int *stb, long int s1, long int s2, int flag)
 helper to create the contengency table for partition matching (k-means) flag define is the list of stable obj must be store to stb, but the size st must be know before.
static void initial_prune (vector< vector< int * > > &Parts, int *dimClasses, int nParts, int K, int T)
 initial_prune removes all classes C from Parts where there does not exist ANY feasible matching containing class C which has weight gt T.
static bool explore (vector< vector< int * > > &Parts, int *dimClasses, int nParts, int K, int T, int partref, int *curintx, int size_curintx, int *next, int size_next, int depth)
 Each class in Parts has its dummy variable set to 0 or 1.
static int generatesubmax (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int n_guesses, int LARGEST_CLASS)
 make an intelligent "guess" at the largest weight of all possible feasible matches.
static void search2 (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *matchlist, int *costlist, int J)
 return the weight of the largest weighted feasible match, along with the match in the (preallocated) argument curmax.
static void explore2 (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *curintx, int size_curintx, int *next, int size_next, int depth, int J, int *matchlist, int *costlist, int *curbranch)
static bool sanitycheck (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *output)
 First element of output is total cost of the matches in the output Second element of output is the total number of matches in output So output has 2+(*(output+1))nParts elements.
static vector< int > bb_enumerateMPI_ (int *argParts, int *dimClasses, int nParts, int K, int T, int n_guesses, int LARGEST_CLASS, int J, int max_branching, float stmult, int branchfunc, int LIM)
 K is the number of classes in each partition (should be the same for all partitions) the first element of each class is its original index in the partition, and second is dummy var MPI: if nTop <= 0, then initial prune is called, and the pruned partitions are returned in a 1D array.
static int * branchMPI (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int curlevel, int n_guesses, int LARGEST_CLASS, int J, int max_branching, float stmult, int branchfunc, int LIM)
 same as branch except the nFirst (=Levels[0]) possibilites for the first match are already chosen firstmatches stores the matches and corresponding cost, where each match is preceded by its cost.
static int branch_factor_2 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, int LIM)
static int branch_factor_3 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, int K, int LIM)
static int branch_factor_4 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, float stmult)
static vector< double > cml_weights (const vector< float > &cml)
static vector< int > cml_line_insino (vector< float > Rot, int i_prj, int n_prj)
 2009-03-25 15:35:53 JB.
static vector< int > cml_line_insino_all (vector< float > Rot, vector< int > seq, int n_prj, int n_lines)
 2009-03-30 15:35:07 JB.
static vector< double > cml_init_rot (vector< float > Ori)
 2009-03-25 15:35:05 JB.
static vector< float > cml_update_rot (vector< float > Rot, int iprj, float nph, float th, float nps)
 2009-03-25 15:35:37 JB.
static vector< double > cml_line_in3d (vector< float > Ori, vector< int > seq, int nprj, int nlines)
 2009-03-26 10:46:14 JB.
static vector< double > cml_spin_psi (const vector< EMData * > &data, vector< int > com, vector< float > weights, int iprj, vector< int > iw, int n_psi, int d_psi, int n_prj)
 2009-03-26 11:37:53 JB.
static double cml_disc (const vector< EMData * > &data, vector< int > com, vector< int > seq, vector< float > weights, int n_lines)
 2009-03-30 15:44:05 JB.
static void set_line (EMData *img, int posline, EMData *line, int offset, int length)
 This function drop a line (line) to an 2D image (img).
static void cml_prepare_line (EMData *sino, EMData *line, int ilf, int ihf, int pos_line, int nblines)
 This function prepare the line from sinogram by cutting off some frequencies, and creating the mirror part (complexe conjugate of the first part).
static EMDatadecimate (EMData *img, int x_step, int y_step=1, int z_step=1)
static 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)
static 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")
static vector< float > histogram (EMData *image, EMData *mask, int nbins=128, float hmin=0.0f, float hmax=0.0f)
static Dict histc (EMData *ref, EMData *img, EMData *mask)
static float hist_comp_freq (float PA, float PB, size_t size_img, int hist_len, EMData *img, vector< float > ref_freq_hist, EMData *mask, float ref_h_diff, float ref_h_min)
static float tf (float dzz, float ak, float voltage=300.0f, float cs=2.0f, float wgh=0.1f, float b_factor=0.0f, float sign=-1.0f)
static EMDatacompress_image_mask (EMData *image, EMData *mask)
static EMDatareconstitute_image_mask (EMData *image, EMData *mask)
 Recreates a n-d image using its compressed 1-D form and the mask.
static vector< float > merge_peaks (vector< float > peak1, vector< float > peak2, float p_size)
static vector< float > pw_extract (vector< float >pw, int n, int iswi, float ps)
static vector< float > call_cl1 (long int *k, long int *n, float *ps, long int *iswi, float *pw, float *q2, double *q, double *x, double *res, double *cu, double *s, long int *iu)
static vector< float > lsfit (long int *ks, long int *n, long int *klm2d, long int *iswi, float *q1, double *q, double *x, double *res, double *cu, double *s, long int *iu)
static void cl1 (long int *k, long int *l, long int *m, long int *n, long int *klm2d, double *q, double *x, double *res, double *cu, long int *iu, double *s)
static float eval (char *images, EMData *img, vector< int > S, int N, int K, int size)
static vector< double > vrdg (const vector< float > &ph, const vector< float > &th)
static void hsortd (double *theta, double *phi, int *key, int len, int option)
static void voronoidiag (double *theta, double *phi, double *weight, int n)
static void voronoi (double *phi, double *theta, double *weight, int nt)
static void disorder2 (double *x, double *y, int *key, int len)
static void ang_to_xyz (double *x, double *y, double *z, int len)
static void flip23 (double *x, double *y, double *z, int *key, int k, int len)
static bool cmp1 (tmpstruct tmp1, tmpstruct tmp2)
static bool cmp2 (tmpstruct tmp1, tmpstruct tmp2)
static int trmsh3_ (int *n0, double *tol, double *x, double *y, double *z__, int *n, int *list, int *lptr, int *lend, int *lnew, int *indx, int *lcnt, int *near__, int *next, double *dist, int *ier)
static double areav_ (int *k, int *n, double *x, double *y, double *z__, int *list, int *lptr, int *lend, int *ier)
static EMDatamadn_scalar (EMData *img, EMData *img1, float scalar)
static EMDatamult_scalar (EMData *img, float scalar)
static EMDataaddn_img (EMData *img, EMData *img1)
static EMDatasubn_img (EMData *img, EMData *img1)
static EMDatamuln_img (EMData *img, EMData *img1)
static EMDatadivn_img (EMData *img, EMData *img1)
static EMDatadivn_filter (EMData *img, EMData *img1)
static void mad_scalar (EMData *img, EMData *img1, float scalar)
static void mul_scalar (EMData *img, float scalar)
static void add_img (EMData *img, EMData *img1)
static void add_img_abs (EMData *img, EMData *img1)
static void add_img2 (EMData *img, EMData *img1)
static void sub_img (EMData *img, EMData *img1)
static void mul_img (EMData *img, EMData *img1)
static void div_img (EMData *img, EMData *img1)
static void div_filter (EMData *img, EMData *img1)
static EMDatapack_complex_to_real (EMData *img)
static vector< float > multiref_polar_ali_2d (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny)
 formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
static vector< float > multiref_polar_ali_2d_peaklist (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny)
static vector< int > assign_groups (vector< float > d, int nref, int nima)
static vector< float > multiref_polar_ali_2d_delta (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, float delta_start, float delta)
 formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
static vector< float > multiref_polar_ali_2d_nom (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny)
 formerly known as apnq DO NOT CONSIDER MIRROR Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
static vector< float > multiref_polar_ali_2d_local (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, string mode, vector< int >numr, float cnx, float cny)
 formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
static vector< float > multiref_polar_ali_helical (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float psi_max, string mode, vector< int >numr, float cnx, float cny, int ynumber=-1)
 formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation Search for peaks only within +/-psi_max from 0 and 180 (helical)
static vector< float > multiref_polar_ali_2d_local_psi (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, float psi_max, string mode, vector< int >numr, float cnx, float cny)
 formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
static void multiref_peaks_ali2d (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, EMData *peaks, EMData *peakm)
 Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08.
static void multiref_peaks_compress_ali2d (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, EMData *peaks, EMData *peakm, EMData *peaks_compress, EMData *peakm_compress)
 Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08.
static vector< float > ali2d_ccf_list (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, double T)
 Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation.
static vector< float > twoD_fine_ali (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys)
static vector< float > twoD_fine_ali_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys)
static vector< float > twoD_to_3D_ali (EMData *volft, Util::KaiserBessel &kb, EMData *refim, EMData *mask, float phi, float theta, float psi, float sxs, float sxy)
static vector< float > twoD_fine_ali_SD (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys)
static float ccc_images (EMData *, EMData *, EMData *, float, float, float)
static vector< float > twoD_fine_ali_SD_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys)
static float ccc_images_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sx, float sy)
static EMDatamove_points (EMData *img, float qprob, int ri, int ro)
static EMDataget_biggest_cluster (EMData *mg)
static 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)
static int mono (int k1, int k2)
static int nint180 (float arg)
static float mean (float *x, int n)
static float var (float *x, int n)
static void rot_shift (float x, float y, float alpha, float x0, float y0, float *x1, float *y1)
static vector< float > multi_align_error (vector< float > args, vector< float > all_ali_params)
static float multi_align_error_func (double *x, vector< float > all_ali_params, int nima, int num_ali)
static void multi_align_error_dfunc (double *x, vector< float > all_ali_params, int nima, int num_ali, double *g)
static vector< float > cluster_pairwise (EMData *d, int K, float T, float F)
static vector< float > cluster_equalsize (EMData *d)
static vector< float > vareas (EMData *d)
static 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.
static void image_mutation (EMData *img, float mutation_rate)
static void array_mutation (float *list, int len_list, float mutation_rate, float min_val, float max_val, int K, int is_mirror)
 The purpose of this function is to convert a list to grey code and mutate them and convert them back.
static vector< float > list_mutation (vector< float > list, float mutation_rate, float min_val, float max_val, int K, int is_mirror)
static float restrict1 (float x, int nx)
static void ap2ri (float *data, size_t n)
 convert complex data array from Amplitude/Phase format into Real/Imaginary format.
static void flip_complex_phase (float *data, size_t n)
 flip the phase of a complex data array.
static void rotate_phase_origin (float *data, size_t nx, size_t ny, size_t nz)
 rotate data vertically by ny/2, to make the mrc phase origin compliance with EMAN1 and TNF reader
static int file_lock_wait (FILE *file)
 lock a file.
static bool check_file_by_magic (const void *first_block, const char *magic)
 check whether a file starts with certain magic string.
static bool is_file_exist (const string &filename)
 check whether a file exists or not
static void flip_image (float *data, size_t nx, size_t ny)
 Vertically flip the data of a 2D real image.
static vector< EMData * > svdcmp (const vector< EMData * > &data, int nvec)
 Perform singular value decomposition on a set of images.
static string str_to_lower (const string &s)
 Return a lower case version of the argument string.
static bool sstrncmp (const char *s1, const char *s2)
 Safe string compare.
static string int2str (int n)
 Get a string format of an integer, e.g.
static string get_line_from_string (char **str)
 Extract a single line from a multi-line string.
static bool get_str_float (const char *str, const char *float_var, float *p_val)
 Extract the float value from a variable=value string with format like "XYZ=1.1", where 'str' is "XYZ=1.1"; 'float_var' is "XYZ="; 'p_val' points to float number 1.1.
static bool get_str_float (const char *str, const char *float_var, float *p_v1, float *p_v2)
 Extract the float values from a variable=value1,value2 string with format like "XYZ=1.1,1.2", where 'str' is "XYZ=1.1,1.2"; 'float_var' is "XYZ="; 'p_v1' points to 1.1; 'p_v2' points to 1.2.
static bool get_str_float (const char *str, const char *float_var, int *p_nvalues, float *p_v1, float *p_v2)
 Extract number of values and the float values, if any, from a string whose format is either "variable=value1,value2 " or "variable".
static bool get_str_int (const char *str, const char *int_var, int *p_val)
 Extract the int value from a variable=value string with format like "XYZ=1", where 'str' is "XYZ=1"; 'int_var' is "XYZ="; 'p_val' points to float number 1.
static bool get_str_int (const char *str, const char *int_var, int *p_v1, int *p_v2)
 Extract the int value from a variable=value1,value2 string with format like "XYZ=1,2", where 'str' is "XYZ=1,2"; 'int_var' is "XYZ="; 'p_val' points to float number 1.
static bool get_str_int (const char *str, const char *int_var, int *p_nvalues, int *p_v1, int *p_v2)
 Extract number of values and the int values, if any, from a string whose format is either "variable=value1,value2 " or "variable".
static string change_filename_ext (const string &old_filename, const string &new_ext)
 Change a file's extension and return the new filename.
static string remove_filename_ext (const string &filename)
 Remove a filename's extension and return the new filename.
static string get_filename_ext (const string &filename)
 Get a filename's extension.
static string sbasename (const string &filename)
 Get a filename's basename.
static void calc_least_square_fit (size_t nitems, const float *data_x, const float *data_y, float *p_slope, float *p_intercept, bool ignore_zero, float absmax=0)
 calculate the least square fit value.
static Vec3f calc_bilinear_least_square (const vector< float > &points)
 calculate bilinear least-square fit, z = a + b x + c y Takes a set of x,y,z vectors and produces an a,b,c vector does not accept error bars on z or return goodness of fit
static void save_data (const vector< float > &x_array, const vector< float > &y_array, const string &filename)
 Save (x y) data array into a file.
static void save_data (float x0, float dx, const vector< float > &y_array, const string &filename)
 Save x, y data into a file.
static void save_data (float x0, float dx, float *y_array, size_t array_size, const string &filename)
 Save x, y data into a file.
static void sort_mat (float *left, float *right, int *leftPerm, int *rightPerm)
 does a sort as in Matlab.
static unsigned long int get_randnum_seed ()
 Get the seed for Randnum class.
static void set_randnum_seed (unsigned long int seed)
 Set the seed for Randnum class.
static int get_irand (int low, int high)
 Get an integer random number between low and high, [low, high].
static float get_frand (int low, int high)
 Get a float random number between low and high, [low, high).
static float get_frand (float low, float high)
 Get a float random number between low and high, [low, high).
static float get_frand (double low, double high)
 Get a float random number between low and high, [low, high).
static float get_gauss_rand (float mean, float sigma)
 Get a Gaussian random number.
static int round (float x)
 Get ceiling round of a float number x.
static int round (double x)
 Get ceiling round of a float number x.
static float linear_interpolate (float p1, float p2, float t)
 Calculate linear interpolation.
static float bilinear_interpolate (float p1, float p2, float p3, float p4, float t, float u)
 Calculate bilinear interpolation.
static float trilinear_interpolate (float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8, float t, float u, float v)
 Calculate trilinear interpolation.
static void find_max (const float *data, size_t nitems, float *p_max_val, int *p_max_index=0)
 Find the maximum value and (optional) its index in an array.
static void find_min_and_max (const float *data, size_t nitems, float *p_max_val, float *p_min_val, int *p_max_index=0, int *p_min_index=0)
 Find the maximum value and (optional) its index, minimum value and (optional) its index in an array.
static Dict get_stats (const vector< float > &data)
 Get the mean, standard deviation, skewness and kurtosis of the input data.
static Dict get_stats_cstyle (const vector< float > &data)
 Performs the same calculations as in get_stats, but uses a single pass, optimized c approach Should perform better than get_stats.
static int calc_best_fft_size (int low)
 Search the best FFT size with good primes.
static EMDatacalc_bessel (const int n, const float &x)
static int square (int n)
 Calculate a number's square.
static float square (float x)
 Calculate a number's square.
static float square (double x)
 Calculate a number's square.
static float square_sum (float x, float y)
 Calcuate (x*x + y*y).
static float hypot2 (float x, float y)
 Euclidean distance function in 2D: f(x,y) = sqrt(x*x + y*y);.
static int hypot3sq (int x, int y, int z)
 Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
static float hypot3sq (float x, float y, float z)
 Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
static float hypot3 (int x, int y, int z)
 Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
static float hypot3 (float x, float y, float z)
 Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
static float hypot3 (double x, double y, double z)
 Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
static float hypot_fast (int x, int y)
 Euclidean distance in 2D for integers computed fast using a cached lookup table.
static short hypot_fast_int (int x, int y)
 Euclidean distance in 2D for integers computed fast using a cached lookup table.
static int fast_floor (float x)
 A fast way to calculate a floor, which is largest integral value not greater than argument.
static float fast_exp (const float &f)
 Returns an approximate of exp(x) using a cached table uses actual exp(x) outside the cached range.
static float fast_acos (const float &f)
 Returns an approximate of acos(x) using a cached table and linear interpolation tolerates values very slightly outside the -1 - 1 range (returning 0).
static float agauss (float a, float dx, float dy, float dz, float d)
 Calculate Gaussian value.
static int get_min (int f1, int f2)
 Get the minimum of 2 numbers.
static int get_min (int f1, int f2, int f3)
 Get the minimum of 3 numbers.
static float get_min (float f1, float f2)
 Get the minimum of 2 numbers.
static float get_min (float f1, float f2, float f3)
 Get the minimum of 3 numbers.
static float get_min (float f1, float f2, float f3, float f4)
 Get the minimum of 4 numbers.
static float get_max (float f1, float f2)
 Get the maximum of 2 numbers.
static float get_max (float f1, float f2, float f3)
 Get the maximum of 3 numbers.
static float get_max (float f1, float f2, float f3, float f4)
 Get the maximum of 4 numbers.
static float angle_sub_2pi (float x, float y)
 Calculate the difference of 2 angles and makes the equivalent result to be less than Pi.
static float angle_sub_pi (float x, float y)
 Calculate the difference of 2 angles and makes the equivalent result to be less than Pi/2.
static float angle_err_ri (float r1, float i1, float r2, float i2)
 Calculate the angular phase difference between two r/i vectors.
static int goodf (const float *p_f)
 Check whether a number is a good float.
static int goodf (const double *p_f)
static string recv_broadcast (int port)
static string get_time_label ()
 Get the current time in a string with format "mm/dd/yyyy hh:mm".
static void set_log_level (int argc, char *argv[])
 Set program logging level through command line option "-v N", where N is the level.
static float eman_copysign (float a, float b)
 copy sign of a number.
static float eman_erfc (float x)
 complementary error function.
static void equation_of_plane (const Vec3f &p1, const Vec3f &p2, const Vec3f &p3, float *plane)
 Determine the equation of a plane that intersects 3 points in 3D space.
static bool point_is_in_convex_polygon_2d (const Vec2f &p1, const Vec2f &p2, const Vec2f &p3, const Vec2f &p4, const Vec2f &actual_point)
 Determines if a point is in a 2D convex polygon described by 4 points using the Barycentric method, which is a fast way of performing the query.
static bool point_is_in_triangle_2d (const Vec2f &p1, const Vec2f &p2, const Vec2f &p3, const Vec2f &actual_point)
 Determines if a point is in a 2D triangle using the Barycentric method, which is a fast way of performing the query Triangle points can be specified in any order.
static void printMatI3D (MIArray3D &mat, const string str=string(""), ostream &out=std::cout)
 Print a 3D integer matrix to a file stream (std out by default).
template<class T>
static T sgn (T &val)
 Sign function.
static float * getBaldwinGridWeights (const int &freq_cutoff, const float &P, const float &r, const float &dfreq=1, const float &alpha=0.5, const float &beta=0.2)
static bool IsPower2 (int x)
 Return true if an integer is positive and is power of 2.
static void apply_precision (float &value, const float &precision)

Static Private Member Functions

static float ang_n (float peakp, string mode, int maxrin)

Classes

class  FakeKaiserBessel
class  Gaussian
 Gaussian function class. More...
class  KaiserBessel
 1-D Kaiser-Bessel window function class. More...
class  sincBlackman
struct  tmpstruct


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

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update().

17493 {
17494         ENTERFUNC;
17495         /* Exception Handle */
17496         if (!img) {
17497                 throw NullPointerException("NULL input image");
17498         }
17499         /* ========= img += img1 ===================== */
17500 
17501         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17502         size_t size = (size_t)nx*ny*nz;
17503         float *img_ptr  = img->get_data();
17504         float *img1_ptr = img1->get_data();
17505         for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i];
17506         img->update();
17507 
17508         EXITFUNC;
17509 }

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

Definition at line 17530 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update().

17531 {
17532         ENTERFUNC;
17533         /* Exception Handle */
17534         if (!img) {
17535                 throw NullPointerException("NULL input image");
17536         }
17537         /* ========= img += img1**2 ===================== */
17538 
17539         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17540         size_t size = (size_t)nx*ny*nz;
17541         float *img_ptr  = img->get_data();
17542         float *img1_ptr = img1->get_data();
17543         if(img->is_complex()) {
17544                 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] ;
17545         } else {
17546                 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i]*img1_ptr[i];
17547         }
17548         img->update();
17549 
17550         EXITFUNC;
17551 }

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

Definition at line 17511 of file util_sparx.cpp.

References abs, ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update().

17512 {
17513         ENTERFUNC;
17514         /* Exception Handle */
17515         if (!img) {
17516                 throw NullPointerException("NULL input image");
17517         }
17518         /* ========= img += img1 ===================== */
17519 
17520         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17521         size_t size = (size_t)nx*ny*nz;
17522         float *img_ptr  = img->get_data();
17523         float *img1_ptr = img1->get_data();
17524         for (size_t i=0;i<size;++i) img_ptr[i] += abs(img1_ptr[i]);
17525         img->update();
17526 
17527         EXITFUNC;
17528 }

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

Definition at line 17309 of file util_sparx.cpp.

References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update().

17310 {
17311         ENTERFUNC;
17312         /* Exception Handle */
17313         if (!img) {
17314                 throw NullPointerException("NULL input image");
17315         }
17316         /* ==============   output = img + img1   ================ */
17317 
17318         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17319         size_t size = (size_t)nx*ny*nz;
17320         EMData * img2 = img->copy_head();
17321         float *img_ptr  =img->get_data();
17322         float *img2_ptr = img2->get_data();
17323         float *img1_ptr = img1->get_data();
17324         for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i];
17325         img2->update();
17326         if(img->is_complex()) {
17327                 img2->set_complex(true);
17328                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17329         }
17330 
17331         EXITFUNC;
17332         return img2;
17333 }

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

Calculate Gaussian value.

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

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 1711 of file util.h.

Referenced by EMAN::FourierReconstructorSimple2D::insert_slice(), and EMAN::GaussFFTProjector::interp_ft_3d().

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

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

Definition at line 18515 of file util_sparx.cpp.

References Crosrng_msg_vec(), Frngs(), get_frand(), ccf_point::i, ccf_point::j, ccf_point::k, ccf_point::mirror, Polar2Dm(), t, and ccf_point::value.

18517                                                                            {
18518 
18519         int   maxrin = numr[numr.size()-1];
18520 
18521         int   ky = int(2*yrng/step+0.5)/2;
18522         int   kx = int(2*xrng/step+0.5)/2;
18523 
18524         float *p_ccf1ds = (float *)malloc(maxrin*sizeof(float));
18525         float *p_ccf1dm = (float *)malloc(maxrin*sizeof(float));
18526         int vol = maxrin*(2*kx+1)*(2*ky+1);
18527         vector<ccf_point> ccf(2*vol);
18528         ccf_point temp;
18529 
18530         int index = 0;
18531         for (int i = -ky; i <= ky; i++) {
18532                 float iy = i * step;
18533                 for (int j = -kx; j <= kx; j++) {
18534                         float ix = j*step;
18535                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18536                         Frngs(cimage, numr);
18537                         Crosrng_msg_vec(crefim, cimage, numr, p_ccf1ds, p_ccf1dm);
18538                         for (int k=0; k<maxrin; k++) {
18539                                 temp.value = p_ccf1ds[k];
18540                                 temp.i = k;
18541                                 temp.j = j;
18542                                 temp.k = i;
18543                                 temp.mirror = 0;
18544                                 ccf[index] = temp;
18545                                 index++;
18546                                 temp.value = p_ccf1dm[k];
18547                                 temp.mirror = 1;
18548                                 ccf[index] = temp;
18549                                 index++;
18550                         }
18551                         delete cimage; cimage = 0;
18552                 }
18553         }
18554 
18555         delete p_ccf1ds;
18556         delete p_ccf1dm;
18557         std::sort(ccf.begin(), ccf.end(), ccf_value());
18558 
18559         double qt = (double)ccf[0].value;
18560         vector <double> p(2*vol), cp(2*vol);
18561 
18562         double sump = 0.0;
18563         for (int i=0; i<2*vol; i++) {
18564                 p[i] = pow(double(ccf[i].value)/qt, 1.0/T);
18565                 sump += p[i];
18566         }
18567         for (int i=0; i<2*vol; i++) {
18568                 p[i] /= sump;
18569         }
18570         for (int i=1; i<2*vol; i++) {
18571                 p[i] += p[i-1];
18572         }
18573         p[2*vol-1] = 2.0;
18574 
18575         float t = get_frand(0.0f, 1.0f);
18576         int select = 0;
18577         while (p[select] < t)   select += 1;
18578 
18579         vector<float> a(6);
18580         a[0] = ccf[select].value;
18581         a[1] = (float)ccf[select].i;
18582         a[2] = (float)ccf[select].j;
18583         a[3] = (float)ccf[select].k;
18584         a[4] = (float)ccf[select].mirror;
18585         a[5] = (float)select;
18586         return a;
18587 }

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(), 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 17739 of file util_sparx.cpp.

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

17740 {
17741     if (mode == "f" || mode == "F")
17742         return fmodf(((peakp-1.0f) / maxrin+1.0f)*360.0f,360.0f);
17743     else
17744         return fmodf(((peakp-1.0f) / maxrin+1.0f)*180.0f,180.0f);
17745 }

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

Definition at line 7685 of file util_sparx.cpp.

References dgr_to_rad, ENTERFUNC, and EXITFUNC.

07686 {
07687         ENTERFUNC;
07688         double costheta,sintheta,cosphi,sinphi;
07689         for(int i = 0;  i<len;  i++)
07690         {
07691                 cosphi = cos(y[i]*dgr_to_rad);
07692                 sinphi = sin(y[i]*dgr_to_rad);
07693                 if(fabs(x[i]-90.0)< 1.0e-5){
07694                         x[i] = cosphi;
07695                         y[i] = sinphi;
07696                         z[i] = 0.0;
07697                 }
07698                 else{
07699                         costheta = cos(x[i]*dgr_to_rad);
07700                         sintheta = sin(x[i]*dgr_to_rad);
07701                         x[i] = cosphi*sintheta;
07702                         y[i] = sinphi*sintheta;
07703                         z[i] = costheta;
07704                 }
07705         }
07706         EXITFUNC;
07707 }

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

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

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

Definition at line 1881 of file util.h.

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

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

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

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

Definition at line 1849 of file util.h.

Referenced by EMAN::EMData::common_lines().

static 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 1866 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, and NullPointerException.

00068 {
00069         Assert(n > 0);
00070 
00071         if (!data) {
00072                 throw NullPointerException("pixel data array");
00073         }
00074 
00075         for (size_t i = 0; i < n; i += 2) {
00076                 float f = data[i] * sin(data[i + 1]);
00077                 data[i] = data[i] * cos(data[i + 1]);
00078                 data[i + 1] = f;
00079         }
00080 }

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

Definition at line 2104 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 8750 of file util_sparx.cpp.

References areas_(), circum_(), FALSE_, ierr, and TRUE_.

Referenced by voronoi().

08753 {
08754     /* Initialized data */
08755 
08756     static double amax = 6.28;
08757 
08758     /* System generated locals */
08759     double ret_val;
08760 
08761     /* Local variables */
08762     static double a, c0[3], c2[3], c3[3];
08763     static int n1, n2, n3;
08764     static double v1[3], v2[3], v3[3];
08765     static int lp, lpl, ierr;
08766     static double asum;
08767     extern double areas_(double *, double *, double *);
08768     static long int first;
08769     extern /* Subroutine */ int circum_(double *, double *,
08770             double *, double *, int *);
08771 
08772 
08773 /* *********************************************************** */
08774 
08775 /*                                            Robert J. Renka */
08776 /*                                  Dept. of Computer Science */
08777 /*                                       Univ. of North Texas */
08778 /*                                           renka@cs.unt.edu */
08779 /*                                                   10/25/02 */
08780 
08781 /*   Given a Delaunay triangulation and the index K of an */
08782 /* interior node, this subroutine returns the (surface) area */
08783 /* of the Voronoi region associated with node K.  The Voronoi */
08784 /* region is the polygon whose vertices are the circumcenters */
08785 /* of the triangles that contain node K, where a triangle */
08786 /* circumcenter is the point (unit vector) lying at the same */
08787 /* angular distance from the three vertices and contained in */
08788 /* the same hemisphere as the vertices. */
08789 
08790 
08791 /* On input: */
08792 
08793 /*       K = Nodal index in the range 1 to N. */
08794 
08795 /*       N = Number of nodes in the triangulation.  N > 3. */
08796 
08797 /*       X,Y,Z = Arrays of length N containing the Cartesian */
08798 /*               coordinates of the nodes (unit vectors). */
08799 
08800 /*       LIST,LPTR,LEND = Data structure defining the trian- */
08801 /*                        gulation.  Refer to Subroutine */
08802 /*                        TRMESH. */
08803 
08804 /* Input parameters are not altered by this function. */
08805 
08806 /* On output: */
08807 
08808 /*       AREAV = Area of Voronoi region K unless IER > 0, */
08809 /*               in which case AREAV = 0. */
08810 
08811 /*       IER = Error indicator: */
08812 /*             IER = 0 if no errors were encountered. */
08813 /*             IER = 1 if K or N is outside its valid range */
08814 /*                     on input. */
08815 /*             IER = 2 if K indexes a boundary node. */
08816 /*             IER = 3 if an error flag is returned by CIRCUM */
08817 /*                     (null triangle). */
08818 /*             IER = 4 if AREAS returns a value greater than */
08819 /*                     AMAX (defined below). */
08820 
08821 /* Modules required by AREAV:  AREAS, CIRCUM */
08822 
08823 /* *********************************************************** */
08824 
08825 
08826 /* Maximum valid triangle area is less than 2*Pi: */
08827 
08828     /* Parameter adjustments */
08829     --lend;
08830     --z__;
08831     --y;
08832     --x;
08833     --list;
08834     --lptr;
08835 
08836     /* Function Body */
08837 
08838 /* Test for invalid input. */
08839 
08840     if (*k < 1 || *k > *n || *n <= 3) {
08841         goto L11;
08842     }
08843 
08844 /* Initialization:  Set N3 to the last neighbor of N1 = K. */
08845 /*   FIRST = TRUE only for the first triangle. */
08846 /*   The Voronoi region area is accumulated in ASUM. */
08847 
08848     n1 = *k;
08849     v1[0] = x[n1];
08850     v1[1] = y[n1];
08851     v1[2] = z__[n1];
08852     lpl = lend[n1];
08853     n3 = list[lpl];
08854     if (n3 < 0) {
08855         goto L12;
08856     }
08857     lp = lpl;
08858     first = TRUE_;
08859     asum = 0.;
08860 
08861 /* Loop on triangles (N1,N2,N3) containing N1 = K. */
08862 
08863 L1:
08864     n2 = n3;
08865     lp = lptr[lp];
08866     n3 = list[lp];
08867     v2[0] = x[n2];
08868     v2[1] = y[n2];
08869     v2[2] = z__[n2];
08870     v3[0] = x[n3];
08871     v3[1] = y[n3];
08872     v3[2] = z__[n3];
08873     if (first) {
08874 
08875 /* First triangle:  compute the circumcenter C3 and save a */
08876 /*   copy in C0. */
08877 
08878         circum_(v1, v2, v3, c3, &ierr);
08879         if (ierr != 0) {
08880             goto L13;
08881         }
08882         c0[0] = c3[0];
08883         c0[1] = c3[1];
08884         c0[2] = c3[2];
08885         first = FALSE_;
08886     } else {
08887 
08888 /* Set C2 to C3, compute the new circumcenter C3, and compute */
08889 /*   the area A of triangle (V1,C2,C3). */
08890 
08891         c2[0] = c3[0];
08892         c2[1] = c3[1];
08893         c2[2] = c3[2];
08894         circum_(v1, v2, v3, c3, &ierr);
08895         if (ierr != 0) {
08896             goto L13;
08897         }
08898         a = areas_(v1, c2, c3);
08899         if (a > amax) {
08900             goto L14;
08901         }
08902         asum += a;
08903     }
08904 
08905 /* Bottom on loop on neighbors of K. */
08906 
08907     if (lp != lpl) {
08908         goto L1;
08909     }
08910 
08911 /* Compute the area of triangle (V1,C3,C0). */
08912 
08913     a = areas_(v1, c3, c0);
08914     if (a > amax) {
08915         goto L14;
08916     }
08917     asum += a;
08918 
08919 /* No error encountered. */
08920 
08921     *ier = 0;
08922     ret_val = asum;
08923     return ret_val;
08924 
08925 /* Invalid input. */
08926 
08927 L11:
08928     *ier = 1;
08929     ret_val = 0.;
08930     return ret_val;
08931 
08932 /* K indexes a boundary node. */
08933 
08934 L12:
08935     *ier = 2;
08936     ret_val = 0.;
08937     return ret_val;
08938 
08939 /* Error in CIRCUM. */
08940 
08941 L13:
08942     *ier = 3;
08943     ret_val = 0.;
08944     return ret_val;
08945 
08946 /* AREAS value larger than AMAX. */
08947 
08948 L14:
08949     *ier = 4;
08950     ret_val = 0.;
08951     return ret_val;
08952 } /* areav_ */

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

References t.

Referenced by image_mutation().

20097                                                                                                                             {
20098 
20099         if (is_mirror != 0) {
20100                 for (int i=0; i<len_list; i++) {
20101                         int r = rand()%10000;
20102                         float f = r/10000.0f;
20103                         if (f < mutation_rate) list[i] = 1-list[i];
20104                 }
20105         } else {
20106                 map<int, vector<int> >  graycode;
20107                 map<vector<int>, int> rev_graycode;
20108                 vector <int> gray;
20109 
20110                 int K=1;
20111                 for (int i=0; i<L; i++) K*=2;
20112 
20113                 for (int k=0; k<K; k++) {
20114                         int shift = 0;
20115                         vector <int> gray;
20116                         for (int i=L-1; i>-1; i--) {
20117                                 int t = ((k>>i)%2-shift)%2;
20118                                 gray.push_back(t);
20119                                 shift += t-2;
20120                         }
20121                         graycode[k] = gray;
20122                         rev_graycode[gray] = k;
20123                 }
20124 
20125                 float gap = (K-1)/(max_val-min_val);
20126                 for (int i=0; i<len_list; i++) {
20127                         float val = list[i];
20128                         if (val < min_val) { val = min_val; }
20129                         else if  (val > max_val) { val = max_val; }
20130                         int k = int((val-min_val)*gap+0.5);
20131                         vector<int> gray = graycode[k];
20132                         bool changed = false;
20133                         for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) {
20134                                 int r = rand()%10000;
20135                                 float f = r/10000.0f;
20136                                 if (f < mutation_rate) {
20137                                         *p = 1-*p;
20138                                         changed = true;
20139                                 }
20140                         }
20141                         if (changed) {
20142                                 k = rev_graycode[gray];
20143                                 list[i] = k/gap+min_val;
20144                         }
20145                 }
20146         }
20147 
20148 }

vector< int > Util::assign_groups ( vector< float >  d,
int  nref,
int  nima 
) [static]

Definition at line 17904 of file util_sparx.cpp.

17904                                                                    {
17905 
17906         int kt = nref;
17907         unsigned int maxasi = nima/nref;
17908 //      vector<int> id_list[nref];
17909         vector< vector<int> > id_list;
17910         id_list.resize(nref);
17911         int group;
17912         while (kt > 0) {
17913                 int l = -1;
17914                 float dmax = -1.e22;
17915                 for (int i=0; i<nref*nima; i++)
17916                         if (d[i] > dmax) {
17917                                 dmax = d[i];
17918                                 l = i;
17919                         }
17920                 group = l/nima;
17921                 int ima  = l%nima;
17922                 id_list[group].push_back(ima);
17923                 if (kt > 1) {
17924                         if (id_list[group].size() < maxasi) group = -1;
17925                         else kt -= 1;
17926                 } else {
17927                         if (id_list[group].size() < maxasi+nima%nref) group = -1;
17928                         else kt -= 1;
17929                 }
17930                 for (int iref=0; iref<nref; iref++) d[iref*nima+ima] = -1.e20;
17931                 if (group != -1) {
17932                         for (int im=0; im<nima; im++) d[group*nima+im] = -1.e20;
17933                 }
17934         }
17935 
17936         vector<int> id_list_1; 
17937         for (int iref=0; iref<nref; iref++)
17938                 for (int im=0; im<maxasi; im++)
17939                         id_list_1.push_back(id_list[iref][im]);
17940         for (int im=maxasi; im<maxasi+nima%nref; im++)
17941                         id_list_1.push_back(id_list[group][im]);
17942         id_list_1.push_back(group);
17943         return id_list_1;
17944 }

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

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

20517                                                           {
20518 
20519         
20520         // 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
20521         // 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
20522         // Make a vector of nParts vectors of K int* each
20523          int* Indices = new int[nParts*K];
20524          int ind_c = 0;
20525          for (int i=0; i < nParts; i++){
20526                  for(int j = 0; j < K; j++){
20527                          Indices[i*K + j] = ind_c;
20528                          ind_c = ind_c + *(dimClasses+i*K + j);
20529 
20530                  }
20531          }
20532 
20533         // do initial pruning on argParts and return the pruned partitions
20534 
20535         // Make a vector of nParts vectors of K int* each
20536         vector <vector <int*> > Parts(nParts,vector<int*>(K));
20537         ind_c = 0;
20538         int argParts_size=0;
20539         for (int i=0; i < nParts; i++){
20540                 for(int j = 0; j < K; j++){
20541                         Parts[i][j]=argParts + ind_c;
20542                         ind_c = ind_c + *(dimClasses+i*K + j);
20543                         argParts_size = argParts_size + *(dimClasses+i*K + j);
20544 
20545                 }
20546         }
20547 
20548         // in the following we call initial_prune with Parts which is a vector. This is not the most
20549         // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and
20550         // 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.....
20551 
20552         // comment out for testing
20553         Util::initial_prune(Parts, dimClasses, nParts, K,T);
20554         for(int i = 0; i < nParts; i++){
20555                 for(int j=0; j < K; j++){
20556                         *(argParts + Indices[i*K + j]+1) = -1;
20557                 }
20558         }
20559 
20560         int num_classes;
20561         int old_index;
20562         for(int i=0; i<nParts; i++){
20563                 num_classes = Parts[i].size();// number of classes in partition i after pruning
20564                 for (int j=0; j < num_classes; j++){
20565                         old_index = *(Parts[i][j]);
20566                         //cout << "old_index: " << old_index<<"\n";
20567                         *(argParts + Indices[i*K + old_index]+1) = 1;
20568                 }
20569         }
20570 
20571 
20572         // if we're not doing mpi then keep going and call branchMPI and return the output
20573         //cout <<"begin partition matching\n";
20574         //int* dummy(0);
20575         int* output = Util::branchMPI(argParts, Indices,dimClasses, nParts, K, T,0,n_guesses,LARGEST_CLASS, J, max_branching, stmult,
20576         branchfunc, LIM);
20577         
20578         //cout<<"total cost: "<<*output<<"\n";
20579         //cout<<"number of matches: "<<*(output+1)<<"\n";
20580         // 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
20581         bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output);
20582 
20583         // something is wrong with output of branchMPI!
20584         if (correct < 1){
20585                 cout << "something is wrong with output of branchMPI!\n";
20586                 vector<int> ret(1);
20587                 ret[0]=-1;
20588                 return ret;
20589         }
20590 
20591         // output is not nonsense, so now put it into a single dimension vector and return
20592         // 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
20593         // and the rest is the list of matches. output is one dimensional
20594 
20595         int output_size = 2+ *(output+1) * nParts;
20596         vector<int> ret(output_size);
20597         for (int i = 0; i < output_size; i++){
20598                 ret[i]=*(output+i);
20599         }
20600         return ret;
20601 
20602 }

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 }

static 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 1482 of file util.h.

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

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

Definition at line 5643 of file util_sparx.cpp.

References B, CUBE, DM, and t.

05644 {
05645 
05646         float  *Bptr = B->get_data();
05647         float  *CUBEptr = CUBE->get_data();
05648 
05649         int NSAM,NROW,NX3D,NY3D,NZC,KZ,IQX,IQY,LDPX,LDPY,LDPZ,LDPNMX,LDPNMY,NZ1;
05650         float DIPX,DIPY,XB,YB,XBB,YBB;
05651 
05652         Transform * t = B->get_attr("xform.projection");
05653         Dict d = t->get_params("spider");
05654         if(t) {delete t; t=0;}
05655         //  Unsure about sign of shifts, check later PAP 06/28/09
05656         float x_shift = d[ "tx" ];
05657         float y_shift = d[ "ty" ];
05658         x_shift = -x_shift;
05659         y_shift = -y_shift;
05660 
05661         NSAM = B->get_xsize();
05662         NROW = B->get_ysize();
05663         NX3D = CUBE->get_xsize();
05664         NY3D = CUBE->get_ysize();
05665         NZC  = CUBE->get_zsize();
05666 
05667 
05668         LDPX   = NX3D/2 +1;
05669         LDPY   = NY3D/2 +1;
05670         LDPZ   = NZC/2 +1;
05671         LDPNMX = NSAM/2 +1;
05672         LDPNMY = NROW/2 +1;
05673         NZ1    = 1;
05674 
05675         for(int K=1;K<=NZC;K++) {
05676                 KZ=K-1+NZ1;
05677                 for(int J=1;J<=NY3D;J++) {
05678                         XBB = (1-LDPX)*DM(1)+(J-LDPY)*DM(2)+(KZ-LDPZ)*DM(3);
05679                         YBB = (1-LDPX)*DM(4)+(J-LDPY)*DM(5)+(KZ-LDPZ)*DM(6);
05680                         for(int I=1;I<=NX3D;I++) {
05681                                 XB  = (I-1)*DM(1)+XBB-x_shift;
05682                                 IQX = int(XB+float(LDPNMX));
05683                                 if (IQX <1 || IQX >= NSAM) continue;
05684                                 YB  = (I-1)*DM(4)+YBB-y_shift;
05685                                 IQY = int(YB+float(LDPNMY));
05686                                 if (IQY<1 || IQY>=NROW)  continue;
05687                                 DIPX = XB+LDPNMX-IQX;
05688                                 DIPY = YB+LDPNMY-IQY;
05689 
05690                                 CUBE(I,J,K) = CUBE(I,J,K)+B(IQX,IQY)+DIPY*(B(IQX,IQY+1)-B(IQX,IQY))+DIPX*(B(IQX+1,IQY)-B(IQX,IQY)+DIPY*(B(IQX+1,IQY+1)-B(IQX+1,IQY)-B(IQX,IQY+1)+B(IQX,IQY)));
05691                         }
05692                 }
05693         }
05694 }

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

References B, and jiafunc().

Referenced by branchMPI().

20772                                                                                                                  {
20773         
20774         int ntot=0;
20775         for (int jit=0; jit < J; jit++){
20776                 if (*(costlist+jit) > T) ntot++;
20777         }
20778 
20779         int cur;
20780         // sort matchlist by cost
20781         int* indx = new int[J];
20782         for (int jit=0; jit < J; jit++) indx[jit]=jit;
20783         vector<int> myindx (indx, indx+J);
20784         vector<int>::iterator it;
20785         costlist_global=costlist;
20786         sort(myindx.begin(), myindx.begin()+J, jiafunc);
20787 
20788         // put matchlist in the order of mycost
20789         int* templist = new int[J];
20790         int* temp2list = new int[J*nParts];
20791         int next = 0;
20792         
20793         for (it=myindx.begin(); it!=myindx.end();++it){
20794                 cur = *(costlist + *it);
20795                 if (cur > T){
20796                         
20797                         templist[next] = cur;
20798                         for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt];
20799                         next = next + 1;
20800                 }
20801         }
20802         
20803         for (int jit=0; jit < ntot; jit++){
20804                 *(costlist+jit)=*(templist + jit);
20805                 //cout <<*(costlist+jit)<<", ";
20806                 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit];
20807         }
20808         //cout <<"\n";
20809         
20810         delete [] indx;
20811         //compute the average 
20812         
20813         // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible
20814         // The number of branches to explore are the mutually exclusive matches. Take the largest of these
20815         
20816         
20817         int B=1;
20818         int B_init=B;
20819         int infeasible=0;
20820         
20821         for (int i=B_init; i<ntot; i++){
20822                 if (i==ntot) continue;
20823                 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to
20824                 // branch on
20825                 infeasible = 0;
20826                 if (LIM < 0) LIM = B;
20827                 for (int j=0; j<B; j++){
20828                         
20829                         for (int vit=0; vit<nParts; vit++){
20830                                 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;}
20831                         }
20832                         if (infeasible >= LIM) break;
20833                 }
20834                 
20835                 if (infeasible >= LIM){
20836                         *(costlist+B)=*(templist+i);
20837                         for (int vit=0; vit < nParts; vit++)
20838                                 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit);
20839                         B=B+1;  
20840                 }
20841         }
20842         
20843         delete [] templist;
20844         delete [] temp2list;
20845         //cout<<"**************************************** "<<B<<" ***************************\n";
20846         
20847         if (branch_all < max_branching){
20848                 if (B>1)
20849                         {branch_all = branch_all + B -1 ; }
20850         }
20851         else B=1;
20852         
20853         return B;
20854         
20855 
20856 }

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

References B, and jiafunc().

Referenced by branchMPI().

20860                                                                                                                       {
20861         
20862         int ntot=0;
20863         for (int jit=0; jit < J; jit++){
20864                 if (*(costlist+jit) > T) ntot++;
20865         }
20866 
20867         int cur;
20868         // sort matchlist by cost
20869         int* indx = new int[J];
20870         for (int jit=0; jit < J; jit++) indx[jit]=jit;
20871         vector<int> myindx (indx, indx+J);
20872         vector<int>::iterator it;
20873         costlist_global=costlist;
20874         sort(myindx.begin(), myindx.begin()+J, jiafunc);
20875 
20876         // put matchlist in the order of mycost
20877         int* templist = new int[J];
20878         int* temp2list = new int[J*nParts];
20879         int next = 0;
20880         
20881         for (it=myindx.begin(); it!=myindx.end();++it){
20882                 cur = *(costlist + *it);
20883                 if (cur > T){
20884                         
20885                         templist[next] = cur;
20886                         for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt];
20887                         next = next + 1;
20888                 }
20889         }
20890         
20891         for (int jit=0; jit < ntot; jit++){
20892                 *(costlist+jit)=*(templist + jit);
20893                 //cout <<*(costlist+jit)<<", ";
20894                 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit];
20895         }
20896         //cout <<"\n";
20897         
20898         delete [] indx;
20899         //compute the average 
20900         
20901         // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible
20902         // The number of branches to explore are the mutually exclusive matches. Take the largest of these
20903         
20904         
20905         int B=1;
20906         int B_init=B;
20907         int infeasible=0;
20908         // if we're near the bottom of the tree then explore more... this is because the larger weights are not likely to change much,
20909         // whereas the smaller ones can have many permutations
20910         if (LIM < 0) LIM = ntot-1;
20911         for (int i=B_init; i<ntot; i++){
20912                 if (i==ntot) continue;
20913                 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to
20914                 // branch on
20915                 infeasible = 0;
20916                 
20917                 for (int j=0; j<ntot; j++){
20918                         if (j == i) continue;
20919                         for (int vit=0; vit<nParts; vit++){
20920                                 if (temp2list[i*nParts+vit] == temp2list[j*nParts+vit]) {infeasible++; break;}
20921                         }
20922                         if (infeasible >= LIM) break;
20923                 }
20924                 
20925                 if (infeasible >= LIM){
20926                         *(costlist+B)=*(templist+i);
20927                         for (int vit=0; vit < nParts; vit++)
20928                                 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit);
20929                         B=B+1;  
20930                 }
20931         }
20932         
20933         delete [] templist;
20934         delete [] temp2list;
20935         //cout<<"**************************************** "<<B<<" ***************************\n";
20936         
20937         
20938         if (branch_all < max_branching){
20939                 if (B>1)
20940                         {branch_all = branch_all + B-1;}
20941         }
20942         else B=1;
20943         
20944         return B;
20945         
20946 
20947 }

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

References B, and jiafunc().

Referenced by branchMPI().

20953                                                                                                                       {
20954         int sum=0;
20955         float average =0;
20956         int ntot=0;
20957         for (int jit=0; jit < J; jit++){
20958                 if (*(costlist+jit) > T) {ntot++; sum = sum +*(costlist+jit);}
20959         }
20960         average = ((float)sum)/((float)ntot);
20961         int cur;
20962         // sort matchlist by cost
20963         int* indx = new int[J];
20964         for (int jit=0; jit < J; jit++) indx[jit]=jit;
20965         vector<int> myindx (indx, indx+J);
20966         vector<int>::iterator it;
20967         costlist_global=costlist;
20968         sort(myindx.begin(), myindx.begin()+J, jiafunc);
20969 
20970         // put matchlist in the order of mycost
20971         int* templist = new int[J];
20972         int* temp2list = new int[J*nParts];
20973         int next = 0;
20974         
20975         for (it=myindx.begin(); it!=myindx.end();++it){
20976                 cur = *(costlist + *it);
20977                 if (cur > T){
20978                         
20979                         templist[next] = cur;
20980                         for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt];
20981                         next = next + 1;
20982                 }
20983         }
20984         
20985         for (int jit=0; jit < ntot; jit++){
20986                 *(costlist+jit)=*(templist + jit);
20987                 //cout <<*(costlist+jit)<<", ";
20988                 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit];
20989         }
20990         //cout <<"\n";
20991         
20992         delete [] indx;
20993         delete [] templist;
20994         delete [] temp2list;
20995         
20996         if (ntot == 1) return 1;
20997         
20998         // look at the average, standard dev etc. If standard dev very small, i.e., costs very similar, then branch on the similar
20999         // costs
21000         float sq_sum=0.0;
21001         //cout <<"costlist:";
21002         for (int i=0; i< ntot; i++){
21003                 sq_sum = sq_sum + (float) pow((float) *(costlist+i) - average, (float)2.0);
21004                 //cout <<*(costlist+i)<<", ";
21005         }       
21006         //cout <<"\n";
21007         
21008         float variance = sq_sum/ntot;
21009         float stdev = (float)pow((float)variance,(float)0.5);
21010         
21011         //cout <<"stdev: "<<int(stdev)<<"\n";
21012         
21013         int B=1;
21014         int largest = *costlist;
21015         //cout <<"largest: "<<largest<<"\n";
21016         for (int i=1; i<ntot; i++){
21017                 int cur = *(costlist+i);
21018                 if (largest-cur < (float)(stdev*stmult)) B++;
21019                 else break;
21020         
21021         }
21022         //cout <<"B: "<<B<<"\n";
21023         if (branch_all < max_branching){
21024                 if (B>1)
21025                         {branch_all = branch_all + B-1;}
21026         }
21027         else B=1;
21028         
21029         return B;
21030         
21031 
21032 }

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

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

20607                                                                                 {
20608 
20609 //*************************************
20610 //testing search2
20611 if (1 == 0){
20612 cout <<"begin test search2\n";
20613 int* matchlist = new int[J*nParts];
20614 int* costlist = new int[J];
20615 for (int jit = 0; jit < nParts; jit++) *(costlist+jit) = 0;
20616 Util::search2(argParts,Indices, dimClasses, nParts, K,  T, matchlist,costlist,J);
20617 
20618 for (int jit = 0; jit < J; jit++) {
20619   cout << *(costlist +jit)<<": ";
20620   for (int yit = 0; yit < nParts; yit++)
20621         cout << *(matchlist + jit*nParts + yit)<<",";
20622   cout <<"\n";  
20623 
20624 }
20625 cout <<"end test search2\n";
20626 int* ret = new int[1];
20627 *ret=1;
20628 delete [] matchlist;
20629 delete [] costlist;
20630 return ret;
20631 }
20632 //**************************************
20633 
20634         // Base Case: we're at a leaf, no more feasible matches possible
20635         if (curlevel > K -1){
20636                 int* res = new int[2];
20637                 *res = 0;
20638                 *(res+1)=0;
20639                 return res;
20640         }
20641 
20642         // branch dynamically depending on results of search 2!
20643         
20644         int* matchlist = new int[J*nParts];
20645         int* costlist = new int[J];
20646         Util::search2(argParts,Indices, dimClasses, nParts, K,  T, matchlist,costlist,J);
20647         
20648         
20649         // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart
20650         // each match contains nParts classes, with the i-th class belonging to the i-th partition.
20651 
20652         // if there are no feasible matches with cost gt T, then return 0
20653         for (int jit = 0; jit < J ; jit++){
20654         
20655                 if (costlist[jit] > T) break;
20656                 if (jit == J-1){
20657                         int* res = new int[2];
20658                         *res = 0;
20659                         *(res+1)=0;
20660                         return res;
20661                 }
20662         }
20663         
20664 
20665         
20666         // note that costlist and matchlist are NOT sorted by weight, and branch factor takes care of that...
20667         if (curlevel==0) branch_all = 0;
20668         int* newcostlist;
20669         int* newmatchlist;
20670         
20671         int nBranches = -1;
20672         
20673         if (branchfunc == 2)
20674                 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
20675 
20676         if (branchfunc == 3)
20677                 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
20678 
20679         if (branchfunc == 4)
20680                 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
20681 
20682         newcostlist= new int[nBranches];
20683         newmatchlist = new int[nBranches*nParts];
20684         for (int i=0; i<nBranches; i++){
20685                 *(newcostlist + i) = *(costlist+i);
20686                 for (int j=0; j< nParts; j++)
20687                         *(newmatchlist + i*nParts + j) = *(matchlist + i*nParts+j);
20688         }
20689 
20690         delete[] costlist;
20691         delete[] matchlist;
20692         
20693         int* maxreturn = new int[2];//initialize to placeholder
20694         *maxreturn=0;
20695         *(maxreturn+1)=0;
20696         // some temporary variables
20697         int old_index;
20698         int totalcost;
20699         int nmatches;
20700         //int offset;
20701 
20702         for(int i=0; i < nBranches ; i++){
20703 
20704                 // consider the i-th match returned by findTopLargest
20705                 //if (newcostlist[i] <= T) continue;
20706 
20707                 // 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.
20708                 // After branch returns, compute overall cost, unmark  the classes just marked as 1 again in preparation for next loop.
20709 
20710                 for(int j=0; j < nParts; j++){
20711                         // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match.
20712                         old_index=newmatchlist[i*nParts + j];
20713                         *(argParts + Indices[j*K+old_index] + 1) = -2;
20714                 }
20715 
20716                 
20717                 int* ret = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T,curlevel+1,n_guesses, LARGEST_CLASS,
20718                 J,max_branching, stmult,branchfunc, LIM);
20719                 
20720                 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret
20721                 totalcost = newcostlist[i] + *ret;
20722 
20723                 //if (curlevel == 0) {
20724                 //      cout <<"totalcost*****************************************************************: "<<totalcost<<", costlist["<<i<<"]="<<newcostlist[i]<<", *ret="<<*ret<<", level: "<<curlevel<<"\n";
20725                         
20726                 //}
20727                 if (totalcost > *maxreturn) // option 1
20728                 {
20729                         nmatches = 1 + *(ret+1);
20730                         delete[] maxreturn; // get rid of the old maxreturn
20731                         maxreturn = new int[2+nmatches*nParts];
20732                         *maxreturn = totalcost;
20733                         
20734                         *(maxreturn + 1)= nmatches;
20735                         int nret = 2+(nmatches-1)*nParts;
20736                         for(int iret=2; iret <nret;iret++) *(maxreturn+iret)=*(ret+iret);
20737                         for(int imax=0; imax<nParts;imax++) *(maxreturn+nret+imax)=newmatchlist[i*nParts + imax];
20738                 }
20739 
20740 
20741                 delete[] ret;
20742 
20743                 // unmark the marked classes in preparation for the next iteration
20744 
20745                 for(int j=0; j < nParts; j++){
20746                         old_index=newmatchlist[i*nParts + j];
20747                         *(argParts + Indices[j*K+old_index] + 1) = 1;
20748                 }
20749 
20750         }
20751 
20752         delete[] newmatchlist;
20753         delete[] newcostlist;
20754         
20755         return maxreturn;
20756 
20757 }

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

int Util::calc_best_fft_size ( int  low  )  [static]

Search the best FFT size with good primes.

It supports FFT size up to 4096 now.

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::FRM2DAligner::align(), EMAN::RTFExhaustiveAligner::align(), EMAN::RotatePrecenterAligner::align(), and EMAN::EMData::unwrap_largerR().

00985 {
00986         Assert(low >= 0);
00987 
00988         //array containing valid sizes <1024 for speed
00989         static char *valid = NULL;
00990 
00991         if (!valid) {
00992                 valid = (char *) calloc(4096, 1);
00993 
00994                 for (float i2 = 1; i2 < 12.0; i2 += 1.0) {
00995 
00996                         float f1 = pow((float) 2.0, i2);
00997                         for (float i3 = 0; i3 < 8.0; i3 += 1.0) {
00998 
00999                                 float f2 = pow((float) 3.0, i3);
01000                                 for (float i5 = 0; i5 < 6.0; i5 += 1.0) {
01001 
01002                                         float f3 = pow((float) 5.0, i5);
01003                                         for (float i7 = 0; i7 < 5.0; i7 += 1.0) {
01004 
01005                                                 float f = f1 * f2 * f3 * pow((float) 7.0, i7);
01006                                                 if (f <= 4095.0) {
01007                                                         int n = (int) f;
01008                                                         valid[n] = 1;
01009                                                 }
01010                                         }
01011                                 }
01012                         }
01013                 }
01014         }
01015 
01016         for (int i = low; i < 4096; i++) {
01017                 if (valid[i]) {
01018                         return i;
01019                 }
01020         }
01021 
01022         LOGERR("Sorry, can only find good fft sizes up to 4096 right now.");
01023 
01024         return 1;
01025 }

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

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

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.

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

References lsfit().

06299 {
06300     long int q2_dim1, q2_offset, q_dim1, q_offset, i__1, i__2;
06301     float r__1;
06302     int tmp__i;
06303     long int i__, j;
06304     --s;
06305     --res;
06306     iu -= 3;
06307     cu -= 3;
06308     --x;
06309     long int klm2d;
06310     klm2d= *k+*k+2;
06311     klm2d=klm2d+klm2d;
06312     q_dim1 = klm2d;
06313     q_offset = 1 + q_dim1;
06314     q -= q_offset;
06315     q2_dim1 = klm2d;
06316     q2_offset = 1 + q2_dim1;
06317     q2 -= q2_offset;
06318     i__2=0;
06319     i__1 = *n - 1;
06320     tmp__i=0;
06321     for (j = 1; j <= i__1; ++j) {
06322         i__2 = *k;
06323         tmp__i+=1;
06324         for (i__ = 1; i__ <= i__2; ++i__) {
06325             r__1 = float(i__ - 1) /(float) *k / (*ps * 2);
06326             q2[i__ + j * q2_dim1] = pow(r__1, tmp__i);
06327         }
06328     }
06329     for  (i__ = 1; i__ <= i__2; ++i__)
06330       { q2[i__ + *n * q2_dim1] = 1.f;
06331             q2[i__ + (*n + 1) * q2_dim1] = pw[i__-1];
06332         }
06333    vector<float> fit_res;
06334    fit_res=Util::lsfit(k, n, &klm2d, iswi, &q2[q2_offset], &q[q_offset], &x[1], &res[1], &cu[3], &s[1], &iu[3]);
06335    return fit_res;
06336 }

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

Definition at line 5595 of file util_sparx.cpp.

References DGR_TO_RAD, DM, and SS.

05596 {
05597         double CPHI,SPHI,CTHE,STHE,CPSI,SPSI;
05598         vector<float>   DM,SS;
05599 
05600         for(int i =0;i<9;i++) DM.push_back(0);
05601 
05602         for(int i =0;i<6;i++) SS.push_back(0);
05603 
05604         CPHI = cos(double(PHI)*DGR_TO_RAD);
05605         SPHI = sin(double(PHI)*DGR_TO_RAD);
05606         CTHE = cos(double(THETA)*DGR_TO_RAD);
05607         STHE = sin(double(THETA)*DGR_TO_RAD);
05608         CPSI = cos(double(PSI)*DGR_TO_RAD);
05609         SPSI = sin(double(PSI)*DGR_TO_RAD);
05610 
05611         SS(1) = float(CPHI);
05612         SS(2) = float(SPHI);
05613         SS(3) = float(CTHE);
05614         SS(4) = float(STHE);
05615         SS(5) = float(CPSI);
05616         SS(6) = float(SPSI);
05617 
05618         DM(1) = float(CPHI*CTHE*CPSI-SPHI*SPSI);
05619         DM(2) = float(SPHI*CTHE*CPSI+CPHI*SPSI);
05620         DM(3) = float(-STHE*CPSI);
05621         DM(4) = float(-CPHI*CTHE*SPSI-SPHI*CPSI);
05622         DM(5) = float(-SPHI*CTHE*SPSI+CPHI*CPSI);
05623         DM(6) = float(STHE*SPSI);
05624         DM(7) = float(STHE*CPHI);
05625         DM(8) = float(STHE*SPHI);
05626         DM(9) = float(CTHE);
05627 
05628         Dict DMnSS;
05629         DMnSS["DM"] = DM;
05630         DMnSS["SS"] = SS;
05631 
05632         return(DMnSS);
05633 }

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

Definition at line 19276 of file util_sparx.cpp.

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

Referenced by twoD_fine_ali_SD().

19276                                                                                                 {
19277 
19278         EMData *rot= new EMData();
19279         float ccc;
19280 
19281         rot = image->rot_scale_trans2D(ang, sx, sy, 1.0);
19282         ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19283         delete rot;
19284         return ccc;
19285 }

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

Definition at line 19313 of file util_sparx.cpp.

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

Referenced by twoD_fine_ali_SD_G().

19313                                                                                                                         {
19314 
19315         EMData *rot= new EMData();
19316         float ccc;
19317 
19318         rot = image->rot_scale_conv7(static_cast<float>(ang*pi/180.0), sx, sy, kb, 1.0f);
19319         ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19320         delete rot;
19321         return ccc;
19322 }

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::PgmIO::is_valid(), EMAN::LstIO::is_valid(), EMAN::LstFastIO::is_valid(), and EMAN::AmiraIO::is_valid().

00195 {
00196         if (!first_block || !magic) {
00197                 throw NullPointerException("first_block/magic");
00198         }
00199 
00200         const char *buf = static_cast < const char *>(first_block);
00201 
00202         if (strncmp(buf, magic, strlen(magic)) == 0) {
00203                 return true;
00204         }
00205         return false;
00206 }

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

Definition at line 6483 of file util_sparx.cpp.

References abs, and in.

06485 {
06486 
06487     long int q_dim1, q_offset, i__1, i__2;
06488     double d__1;
06489 
06490     static long int i__, j;
06491     static double z__;
06492     static long int n1, n2, ia, ii, kk, in, nk, js;
06493     static double sn, zu, zv;
06494     static long int nk1, klm, nkl, jmn, jpn;
06495     static double cuv;
06496     static long int klm1, nkl1, klm2, kode, iimn, nklm, iter;
06497     static float xmin;
06498     static double xmax;
06499     static long int iout;
06500     static double xsum;
06501     static long int iineg, maxit;
06502     static double toler;
06503     static float error;
06504     static double pivot;
06505     static long int kforce, iphase;
06506     static double tpivot;
06507 
06508     --s;
06509     --res;
06510     iu -= 3;
06511     cu -= 3;
06512     --x;
06513     q_dim1 = *klm2d;
06514     q_offset = 1 + q_dim1;
06515     q -= q_offset;
06516 
06517     /* Function Body */
06518     maxit = 500;
06519     kode = 0;
06520     toler = 1e-4f;
06521     iter = 0;
06522     n1 = *n + 1;
06523     n2 = *n + 2;
06524     nk = *n + *k;
06525     nk1 = nk + 1;
06526     nkl = nk + *l;
06527     nkl1 = nkl + 1;
06528     klm = *k + *l + *m;
06529     klm1 = klm + 1;
06530     klm2 = klm + 2;
06531     nklm = *n + klm;
06532     kforce = 1;
06533     iter = 0;
06534     js = 1;
06535     ia = 0;
06536 /* SET UP LABELS IN Q. */
06537     i__1 = *n;
06538     for (j = 1; j <= i__1; ++j) {
06539         q[klm2 + j * q_dim1] = (double) j;
06540 /* L10: */
06541     }
06542     i__1 = klm;
06543     for (i__ = 1; i__ <= i__1; ++i__) {
06544         q[i__ + n2 * q_dim1] = (double) (*n + i__);
06545         if (q[i__ + n1 * q_dim1] >= 0.f) {
06546             goto L30;
06547         }
06548         i__2 = n2;
06549         for (j = 1; j <= i__2; ++j) {
06550             q[i__ + j * q_dim1] = -q[i__ + j * q_dim1];
06551 /* L20: */
06552         }
06553 L30:
06554         ;
06555     }
06556 /* SET UP PHASE 1 COSTS. */
06557     iphase = 2;
06558     i__1 = nklm;
06559     for (j = 1; j <= i__1; ++j) {
06560         cu[(j << 1) + 1] = 0.f;
06561         cu[(j << 1) + 2] = 0.f;
06562         iu[(j << 1) + 1] = 0;
06563         iu[(j << 1) + 2] = 0;
06564 /* L40: */
06565     }
06566     if (*l == 0) {
06567         goto L60;
06568     }
06569     i__1 = nkl;
06570     for (j = nk1; j <= i__1; ++j) {
06571         cu[(j << 1) + 1] = 1.f;
06572         cu[(j << 1) + 2] = 1.f;
06573         iu[(j << 1) + 1] = 1;
06574         iu[(j << 1) + 2] = 1;
06575 /* L50: */
06576     }
06577     iphase = 1;
06578 L60:
06579     if (*m == 0) {
06580         goto L80;
06581     }
06582     i__1 = nklm;
06583     for (j = nkl1; j <= i__1; ++j) {
06584         cu[(j << 1) + 2] = 1.f;
06585         iu[(j << 1) + 2] = 1;
06586         jmn = j - *n;
06587         if (q[jmn + n2 * q_dim1] < 0.f) {
06588             iphase = 1;
06589         }
06590 /* L70: */
06591     }
06592 L80:
06593     if (kode == 0) {
06594         goto L150;
06595     }
06596     i__1 = *n;
06597     for (j = 1; j <= i__1; ++j) {
06598         if ((d__1 = x[j]) < 0.) {
06599             goto L90;
06600         } else if (d__1 == 0) {
06601             goto L110;
06602         } else {
06603             goto L100;
06604         }
06605 L90:
06606         cu[(j << 1) + 1] = 1.f;
06607         iu[(j << 1) + 1] = 1;
06608         goto L110;
06609 L100:
06610         cu[(j << 1) + 2] = 1.f;
06611         iu[(j << 1) + 2] = 1;
06612 L110:
06613         ;
06614     }
06615     i__1 = *k;
06616     for (j = 1; j <= i__1; ++j) {
06617         jpn = j + *n;
06618         if ((d__1 = res[j]) < 0.) {
06619             goto L120;
06620         } else if (d__1 == 0) {
06621             goto L140;
06622         } else {
06623             goto L130;
06624         }
06625 L120:
06626         cu[(jpn << 1) + 1] = 1.f;
06627         iu[(jpn << 1) + 1] = 1;
06628         if (q[j + n2 * q_dim1] > 0.f) {
06629             iphase = 1;
06630         }
06631         goto L140;
06632 L130:
06633         cu[(jpn << 1) + 2] = 1.f;
06634         iu[(jpn << 1) + 2] = 1;
06635         if (q[j + n2 * q_dim1] < 0.f) {
06636             iphase = 1;
06637         }
06638 L140:
06639         ;
06640     }
06641 L150:
06642     if (iphase == 2) {
06643         goto L500;
06644     }
06645 /* COMPUTE THE MARGINAL COSTS. */
06646 L160:
06647     i__1 = n1;
06648     for (j = js; j <= i__1; ++j) {
06649         xsum = 0.;
06650         i__2 = klm;
06651         for (i__ = 1; i__ <= i__2; ++i__) {
06652             ii = (long int) q[i__ + n2 * q_dim1];
06653             if (ii < 0) {
06654                 goto L170;
06655             }
06656             z__ = cu[(ii << 1) + 1];
06657             goto L180;
06658 L170:
06659             iineg = -ii;
06660             z__ = cu[(iineg << 1) + 2];
06661 L180:
06662             xsum += q[i__ + j * q_dim1] * z__;
06663 /*  180       XSUM = XSUM + Q(I,J)*Z */
06664 /* L190: */
06665         }
06666         q[klm1 + j * q_dim1] = xsum;
06667 /* L200: */
06668     }
06669     i__1 = *n;
06670     for (j = js; j <= i__1; ++j) {
06671         ii = (long int) q[klm2 + j * q_dim1];
06672         if (ii < 0) {
06673             goto L210;
06674         }
06675         z__ = cu[(ii << 1) + 1];
06676         goto L220;
06677 L210:
06678         iineg = -ii;
06679         z__ = cu[(iineg << 1) + 2];
06680 L220:
06681         q[klm1 + j * q_dim1] -= z__;
06682 /* L230: */
06683     }
06684 /* DETERMINE THE VECTOR TO ENTER THE BASIS. */
06685 L240:
06686     xmax = 0.f;
06687     if (js > *n) {
06688         goto L490;
06689     }
06690     i__1 = *n;
06691     for (j = js; j <= i__1; ++j) {
06692         zu = q[klm1 + j * q_dim1];
06693         ii = (long int) q[klm2 + j * q_dim1];
06694         if (ii > 0) {
06695             goto L250;
06696         }
06697         ii = -ii;
06698         zv = zu;
06699         zu = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2];
06700         goto L260;
06701 L250:
06702         zv = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2];
06703 L260:
06704         if (kforce == 1 && ii > *n) {
06705             goto L280;
06706         }
06707         if (iu[(ii << 1) + 1] == 1) {
06708             goto L270;
06709         }
06710         if (zu <= xmax) {
06711             goto L270;
06712         }
06713         xmax = zu;
06714         in = j;
06715 L270:
06716         if (iu[(ii << 1) + 2] == 1) {
06717             goto L280;
06718         }
06719         if (zv <= xmax) {
06720             goto L280;
06721         }
06722         xmax = zv;
06723         in = j;
06724 L280:
06725         ;
06726     }
06727     if (xmax <= toler) {
06728         goto L490;
06729     }
06730     if (q[klm1 + in * q_dim1] == xmax) {
06731         goto L300;
06732     }
06733     i__1 = klm2;
06734     for (i__ = 1; i__ <= i__1; ++i__) {
06735         q[i__ + in * q_dim1] = -q[i__ + in * q_dim1];
06736 /* L290: */
06737     }
06738     q[klm1 + in * q_dim1] = xmax;
06739 /* DETERMINE THE VECTOR TO LEAVE THE BASIS. */
06740 L300:
06741     if (iphase == 1 || ia == 0) {
06742         goto L330;
06743     }
06744     xmax = 0.f;
06745     i__1 = ia;
06746     for (i__ = 1; i__ <= i__1; ++i__) {
06747         z__ = (d__1 = q[i__ + in * q_dim1], abs(d__1));
06748         if (z__ <= xmax) {
06749             goto L310;
06750         }
06751         xmax = z__;
06752         iout = i__;
06753 L310:
06754         ;
06755     }
06756     if (xmax <= toler) {
06757         goto L330;
06758     }
06759     i__1 = n2;
06760     for (j = 1; j <= i__1; ++j) {
06761         z__ = q[ia + j * q_dim1];
06762         q[ia + j * q_dim1] = q[iout + j * q_dim1];
06763         q[iout + j * q_dim1] = z__;
06764 /* L320: */
06765     }
06766     iout = ia;
06767     --ia;
06768     pivot = q[iout + in * q_dim1];
06769     goto L420;
06770 L330:
06771     kk = 0;
06772     i__1 = klm;
06773     for (i__ = 1; i__ <= i__1; ++i__) {
06774         z__ = q[i__ + in * q_dim1];
06775         if (z__ <= toler) {
06776             goto L340;
06777         }
06778         ++kk;
06779         res[kk] = q[i__ + n1 * q_dim1] / z__;
06780         s[kk] = (double) i__;
06781 L340:
06782         ;
06783     }
06784 L350:
06785     if (kk > 0) {
06786         goto L360;
06787     }
06788     kode = 2;
06789     goto L590;
06790 L360:
06791     xmin = static_cast<float>( res[1] );
06792     iout = (long int) s[1];
06793     j = 1;
06794     if (kk == 1) {
06795         goto L380;
06796     }
06797     i__1 = kk;
06798     for (i__ = 2; i__ <= i__1; ++i__) {
06799         if (res[i__] >= xmin) {
06800             goto L370;
06801         }
06802         j = i__;
06803         xmin = static_cast<float>( res[i__] );
06804         iout = (long int) s[i__];
06805 L370:
06806         ;
06807     }
06808     res[j] = res[kk];
06809     s[j] = s[kk];
06810 L380:
06811     --kk;
06812     pivot = q[iout + in * q_dim1];
06813     ii = (long int) q[iout + n2 * q_dim1];
06814     if (iphase == 1) {
06815         goto L400;
06816     }
06817     if (ii < 0) {
06818         goto L390;
06819     }
06820     if (iu[(ii << 1) + 2] == 1) {
06821         goto L420;
06822     }
06823     goto L400;
06824 L390:
06825     iineg = -ii;
06826     if (iu[(iineg << 1) + 1] == 1) {
06827         goto L420;
06828     }
06829 /* 400 II = IABS(II) */
06830 L400:
06831     ii = abs(ii);
06832     cuv = cu[(ii << 1) + 1] + cu[(ii << 1) + 2];
06833     if (q[klm1 + in * q_dim1] - pivot * cuv <= toler) {
06834         goto L420;
06835     }
06836 /* BYPASS INTERMEDIATE VERTICES. */
06837     i__1 = n1;
06838     for (j = js; j <= i__1; ++j) {
06839         z__ = q[iout + j * q_dim1];
06840         q[klm1 + j * q_dim1] -= z__ * cuv;
06841         q[iout + j * q_dim1] = -z__;
06842 /* L410: */
06843     }
06844     q[iout + n2 * q_dim1] = -q[iout + n2 * q_dim1];
06845     goto L350;
06846 /* GAUSS-JORDAN ELIMINATION. */
06847 L420:
06848     if (iter < maxit) {
06849         goto L430;
06850     }
06851     kode = 3;
06852     goto L590;
06853 L430:
06854     ++iter;
06855     i__1 = n1;
06856     for (j = js; j <= i__1; ++j) {
06857         if (j != in) {
06858             q[iout + j * q_dim1] /= pivot;
06859         }
06860 /* L440: */
06861     }
06862 /* IF PERMITTED, USE SUBROUTINE COL OF THE DESCRIPTION */
06863 /* SECTION AND REPLACE THE FOLLOWING SEVEN STATEMENTS DOWN */
06864 /* TO AND INCLUDING STATEMENT NUMBER 460 BY.. */
06865 /*     DO 460 J=JS,N1 */
06866 /*        IF(J .EQ. IN) GO TO 460 */
06867 /*        Z = -Q(IOUT,J) */
06868 /*        CALL COL(Q(1,J), Q(1,IN), Z, IOUT, KLM1) */
06869 /* 460 CONTINUE */
06870     i__1 = n1;
06871     for (j = js; j <= i__1; ++j) {
06872         if (j == in) {
06873             goto L460;
06874         }
06875         z__ = -q[iout + j * q_dim1];
06876         i__2 = klm1;
06877         for (i__ = 1; i__ <= i__2; ++i__) {
06878             if (i__ != iout) {
06879                 q[i__ + j * q_dim1] += z__ * q[i__ + in * q_dim1];
06880             }
06881 /* L450: */
06882         }
06883 L460:
06884         ;
06885     }
06886     tpivot = -pivot;
06887     i__1 = klm1;
06888     for (i__ = 1; i__ <= i__1; ++i__) {
06889         if (i__ != iout) {
06890             q[i__ + in * q_dim1] /= tpivot;
06891         }
06892 /* L470: */
06893     }
06894     q[iout + in * q_dim1] = 1.f / pivot;
06895     z__ = q[iout + n2 * q_dim1];
06896     q[iout + n2 * q_dim1] = q[klm2 + in * q_dim1];
06897     q[klm2 + in * q_dim1] = z__;
06898     ii = (long int) abs(z__);
06899     if (iu[(ii << 1) + 1] == 0 || iu[(ii << 1) + 2] == 0) {
06900         goto L240;
06901     }
06902     i__1 = klm2;
06903     for (i__ = 1; i__ <= i__1; ++i__) {
06904         z__ = q[i__ + in * q_dim1];
06905         q[i__ + in * q_dim1] = q[i__ + js * q_dim1];
06906         q[i__ + js * q_dim1] = z__;
06907 /* L480: */
06908     }
06909     ++js;
06910     goto L240;
06911 /* TEST FOR OPTIMALITY. */
06912 L490:
06913     if (kforce == 0) {
06914         goto L580;
06915     }
06916     if (iphase == 1 && q[klm1 + n1 * q_dim1] <= toler) {
06917         goto L500;
06918     }
06919     kforce = 0;
06920     goto L240;
06921 /* SET UP PHASE 2 COSTS. */
06922 L500:
06923     iphase = 2;
06924     i__1 = nklm;
06925     for (j = 1; j <= i__1; ++j) {
06926         cu[(j << 1) + 1] = 0.f;
06927         cu[(j << 1) + 2] = 0.f;
06928 /* L510: */
06929     }
06930     i__1 = nk;
06931     for (j = n1; j <= i__1; ++j) {
06932         cu[(j << 1) + 1] = 1.f;
06933         cu[(j << 1) + 2] = 1.f;
06934 /* L520: */
06935     }
06936     i__1 = klm;
06937     for (i__ = 1; i__ <= i__1; ++i__) {
06938         ii = (long int) q[i__ + n2 * q_dim1];
06939         if (ii > 0) {
06940             goto L530;
06941         }
06942         ii = -ii;
06943         if (iu[(ii << 1) + 2] == 0) {
06944             goto L560;
06945         }
06946         cu[(ii << 1) + 2] = 0.f;
06947         goto L540;
06948 L530:
06949         if (iu[(ii << 1) + 1] == 0) {
06950             goto L560;
06951         }
06952         cu[(ii << 1) + 1] = 0.f;
06953 L540:
06954         ++ia;
06955         i__2 = n2;
06956         for (j = 1; j <= i__2; ++j) {
06957             z__ = q[ia + j * q_dim1];
06958             q[ia + j * q_dim1] = q[i__ + j * q_dim1];
06959             q[i__ + j * q_dim1] = z__;
06960 /* L550: */
06961         }
06962 L560:
06963         ;
06964     }
06965     goto L160;
06966 L570:
06967     if (q[klm1 + n1 * q_dim1] <= toler) {
06968         goto L500;
06969     }
06970     kode = 1;
06971     goto L590;
06972 L580:
06973     if (iphase == 1) {
06974         goto L570;
06975     }
06976 /* PREPARE OUTPUT. */
06977     kode = 0;
06978 L590:
06979     xsum = 0.;
06980     i__1 = *n;
06981     for (j = 1; j <= i__1; ++j) {
06982         x[j] = 0.f;
06983 /* L600: */
06984     }
06985     i__1 = klm;
06986     for (i__ = 1; i__ <= i__1; ++i__) {
06987         res[i__] = 0.f;
06988 /* L610: */
06989     }
06990     i__1 = klm;
06991     for (i__ = 1; i__ <= i__1; ++i__) {
06992         ii = (long int) q[i__ + n2 * q_dim1];
06993         sn = 1.f;
06994         if (ii > 0) {
06995             goto L620;
06996         }
06997         ii = -ii;
06998         sn = -1.f;
06999 L620:
07000         if (ii > *n) {
07001             goto L630;
07002         }
07003         x[ii] = sn * q[i__ + n1 * q_dim1];
07004         goto L640;
07005 L630:
07006         iimn = ii - *n;
07007         res[iimn] = sn * q[i__ + n1 * q_dim1];
07008         if (ii >= n1 && ii <= nk) {
07009             xsum += q[i__ + n1 * q_dim1];
07010         }
07011 L640:
07012         ;
07013     }
07014     error = (float)xsum;
07015     return;
07016 }

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

Definition at line 19910 of file util_sparx.cpp.

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

19910                                                {
19911         //  WORKS ONLY FOR NUMBER OF OBJECTS N=l^2   !!
19912         int nx = d->get_xsize();
19913         int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0);
19914         int K = N/2;
19915         vector<float> group(N);
19916         if(N*(N-1)/2 != nx) {
19917                 //print  "  incorrect dimension"
19918                 return group;}
19919         //bool active[N];       //this does not compile in VS2005. --Grant Tang
19920         bool * active = new bool[N];
19921         for(int i=0; i<N; i++) active[i] = true;
19922 
19923         float dm, qd;
19924         int   ppi = 0, ppj = 0;
19925         for(int k=0; k<K; k++) {
19926                 // find pairs of most similiar objects among active
19927                 //cout<<"  k  "<<k<<endl;
19928                 dm = 1.0e23f;
19929                 for(int i=1; i<N; i++) {
19930                         if(active[i]) {
19931                                 for(int j=0; j<i; j++) {
19932                                         if(active[j]) {
19933                                                 qd = (*d)(i*(i - 1)/2 + j);
19934                                                 if(qd < dm) {
19935                                                         dm = qd;
19936                                                         ppi = i;
19937                                                         ppj = j;
19938                                                 }
19939                                         }
19940                                 }
19941                         }
19942                 }
19943                 group[2*k] = float(ppi);
19944                 group[1+2*k] = float(ppj);
19945                 active[ppi] = false;
19946                 active[ppj] = false;
19947         }
19948 
19949         delete [] active;
19950         active = NULL;
19951         return  group;
19952 }

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

Definition at line 19702 of file util_sparx.cpp.

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

19702                                                                        {
19703         int nx = d->get_xsize();
19704         int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0);
19705         vector<float> out(N+K+2);
19706         if(N*(N-1)/2 != nx) {
19707                 //print  "  incorrect dimension"
19708                 return out;}
19709         //  assign random objects as centers
19710         for(int i=0; i<N; i++) assign(i) = float(i);
19711         // shuffle
19712         for(int i=0; i<N; i++) {
19713                 int j = Util::get_irand(0,N-1);
19714                 float temp = assign(i);
19715                 assign(i) = assign(j);
19716                 assign(j) = temp;
19717         }
19718         for(int k=0; k<K; k++) cent(k) = float(assign(k));
19719         //for(int k=0; k<K; k++) cout<<cent(k)<<"    ";cout<<endl;
19720         //
19721         for(int i=0; i<N; i++) assign(i) = 0.0f;
19722         float qm, dispold = 1.1e22f, disp = 1.0e22f, na=0.0f;
19723         bool change = true;
19724         int it = -1;
19725         int ct = -1;
19726         while ((change && disp < dispold) || ct > 0) {
19727 
19728                 change = false;
19729                 dispold = disp;
19730                 it++;
19731 
19732                 // dispersion is a sum of distance from objects to object center
19733                 disp = 0.0f;
19734                 ct = 0;
19735                 for(int i=0; i<N; i++) {
19736                         qm = 1.0e23f;
19737                         for(int k=0; k<K; k++) {
19738                                 if(float(i) == cent(k)) {
19739                                         qm = 0.0f;
19740                                         na = (float)k;
19741                                 } else {
19742                                         float dt = (*d)(mono(i,int(cent(k))));
19743                                         if(dt < qm) {
19744                                                 qm = dt;
19745                                                 na = (float)k;
19746                                         }
19747                                 }
19748                         }
19749 
19750 
19751                         // Simulated annealing
19752                         if(exp(-1.0/float(T)) > Util::get_irand(1,1000)/1000.0) {
19753                             na = (float)(Util::get_irand(0, K));
19754                             qm = (*d)(mono(i,int(na)));
19755                             ct++;
19756                         }
19757 
19758                         disp += qm;
19759 
19760                         if(na != assign(i)) {
19761                                 assign(i) = na;
19762                                 change = true;
19763                         }
19764                 }
19765 
19766                 //cout<<"Iteration:  "<<it<< " disp " <<disp << " T " << T << " disturb " << ct << endl;
19767                 T = T*F;
19768 
19769         //for(int k=0; k<N; k++) cout<<assign(k)<<"    ";cout<<endl;
19770                 //print disp
19771                 //print  assign
19772                 // find centers
19773                 for(int k=0; k<K; k++) {
19774                         qm = 1.0e23f;
19775                         for(int i=0; i<N; i++) {
19776                                 if(assign(i) == float(k)) {
19777                                         float q = 0.0;
19778                                         for(int j=0; j<N; j++) {
19779                                                 if(assign(j) == float(k)) {
19780                                                                 //it cannot be the same object
19781                                                         if(i != j)  q += (*d)(mono(i,j));
19782                                                         //cout<<q<<"   "<<i<<"   "<<j<<"   "<<k<<endl;}
19783                                                 }
19784                                         }
19785                                         if(q < qm) {
19786                                                 //cout<<qm<<"   "<<q<<"   "<<i<<"   "<<k<<endl;
19787                                                 qm = q;
19788                                                 cent(k) = float(i);
19789                                         }
19790                                 }
19791                         }
19792                 }
19793         //for(int k=0; k<K; k++) cout<<cent(k)<<"    ";cout<<endl;cout<<disp<<endl;
19794         }
19795         out[N+K] = disp;
19796         out[N+K+1] = float(it);
19797         return  out;
19798 }

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

04915                                                                                                                        {
04916     double res = 0;
04917     double buf = 0;
04918     float* line_1;
04919     float* line_2;
04920     int i, n, ind;
04921     int lnlen = data[0]->get_xsize();
04922     for (n=0; n<n_lines; ++n) {
04923         ind = n*2;
04924         line_1 = data[seq[ind]]->get_data() + com[ind] * lnlen;
04925         line_2 = data[seq[ind+1]]->get_data() + com[ind+1] *lnlen;
04926         buf = 0;
04927         for (i=0; i<lnlen; ++i) {
04928             buf += (line_1[i]-line_2[i])*(line_1[i]-line_2[i]);
04929         }
04930         res += buf * weights[n];
04931     }
04932 
04933     return res;
04934 
04935 }

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

References deg_rad.

04692                                                   {
04693     int nb_ori = Ori.size() / 4;
04694     int i, ind;
04695     float ph, th, ps;
04696     double cph, cth, cps, sph, sth, sps;
04697     vector<double> Rot(nb_ori*9);
04698     for (i=0; i<nb_ori; ++i){
04699         ind = i*4;
04700         // spider convention phi=psi-90, psi=phi+90
04701         ph = Ori[ind+2]-90;
04702         th = Ori[ind+1];
04703         ps = Ori[ind]+90;
04704         ph *= deg_rad;
04705         th *= deg_rad;
04706         ps *= deg_rad;
04707         // pre-calculate some trigo stuffs
04708         cph = cos(ph);
04709         cth = cos(th);
04710         cps = cos(ps);
04711         sph = sin(ph);
04712         sth = sin(th);
04713         sps = sin(ps);
04714         // fill rotation matrix
04715         ind = i*9;
04716         Rot[ind] = cph*cps-cth*sps*sph;
04717         Rot[ind+1] = cph*sps+cth*cps*sph;
04718         Rot[ind+2] = sth*sph;
04719         Rot[ind+3] = -sph*cps-cth*sps*cph;
04720         Rot[ind+4] = -sph*sps+cth*cps*cph;
04721         Rot[ind+5] = sth*cph;
04722         Rot[ind+6] = sth*sps;
04723         Rot[ind+7] = -sth*cps;
04724         Rot[ind+8] = cth;
04725     }
04726 
04727     return Rot;
04728 }

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

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

04860                                                                                      {
04861     // seq is the pairwise index ij: 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3
04862     vector<double> cml(2*nlines); // [phi, theta] / line
04863     float ph1, th1;
04864     float ph2, th2;
04865     double nx, ny, nz;
04866     double norm;
04867     double sth1=0, sph1=0, cth1=0, cph1=0;
04868     double sth2, sph2, cth2, cph2;
04869     int l, ind, c;
04870     int mem = -1;
04871     for (l=0; l<nlines; ++l){
04872         c = 2*l;
04873         if (seq[c]!=mem){
04874             mem = seq[c];
04875             ind = 4*seq[c];
04876             ph1 = Ori[ind]*deg_rad;
04877             th1 = Ori[ind+1]*deg_rad;
04878             sth1 = sin(th1);
04879             sph1 = sin(ph1);
04880             cth1 = cos(th1);
04881             cph1 = cos(ph1);
04882         }
04883         ind = 4*seq[c+1];
04884         ph2 = Ori[ind]*deg_rad;
04885         th2 = Ori[ind+1]*deg_rad;
04886         sth2 = sin(th2);
04887         cth2 = cos(th2);
04888         sph2 = sin(ph2);
04889         cph2 = cos(ph2);
04890         // cross product
04891         nx = sth1*cph1*cth2 - cth1*sth2*cph2;
04892         ny = cth1*sth2*sph2 - cth2*sth1*sph1;
04893         nz = sth1*sph1*sth2*cph2 - sth1*cph1*sth2*sph2;
04894         norm = sqrt(nx*nx+ny*ny+nz*nz);
04895         nx /= norm;
04896         ny /= norm;
04897         nz /= norm;
04898         // apply mirror if need
04899         if (nz<0) {nx=-nx; ny=-ny; nz=-nz;}
04900         // compute theta and phi
04901         cml[c+1] = acos(nz);
04902         if (cml[c+1] == 0) {cml[c] = 0;}
04903         else {
04904             cml[c+1] *= rad_deg;
04905             if (cml[c+1] > 89.99) {cml[c+1] = 89.99;} // this fix some pb in Voronoi
04906             cml[c] = rad_deg * atan2(nx, ny);
04907             cml[c] = fmod(360 + cml[c], 360);
04908 
04909         }
04910     }
04911 
04912     return cml;
04913 }

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

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

04761                                                                         {
04762     vector<int> com(2*(n_prj - 1));
04763     int a = i_prj*9;
04764     int i, b, c;
04765     int n1=0, n2=0;
04766     float vmax = 1 - 1.0e-6f;
04767     double r11, r12, r13, r23, r31, r32, r33;
04768 
04769     c = 0;
04770     for (i=0; i<n_prj; ++i){
04771         if (i!=i_prj){
04772             b = i*9;
04773             // this is equivalent to R = A*B'
04774             r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2];
04775             r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5];
04776             r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8];
04777             r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8];
04778             r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2];
04779             r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5];
04780             r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8];
04781             if (r33 > vmax) {
04782                 n2 = 270;
04783                 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11)));
04784             }
04785             else if (r33 < -vmax) {
04786                 n2 = 270;
04787                 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11)));
04788             } else {
04789                 n2 = nint180((float)(rad_deg*atan2(r31, -r32)));
04790                 n1 = nint180((float)(rad_deg*atan2(r13, r23)));
04791                 if (n1 < 0) {n1 += 360;}
04792                 if (n2 <= 0) {n2 = abs(n2);}
04793                 else {n2 = 360 - n2;}
04794             }
04795 
04796             if (n1 >= 360){n1 = n1 % 360;}
04797             if (n2 >= 360){n2 = n2 % 360;}
04798 
04799             // store common-lines
04800             b = c*2;
04801             com[b] = n1;
04802             com[b+1] = n2;
04803             ++c;
04804         }
04805     }
04806 
04807     return com;
04808 
04809 }

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

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

04811                                                                                           {
04812     vector<int> com(2*n_lines);
04813     int a=0, b, c, l;
04814     int n1=0, n2=0, mem=-1;
04815     float vmax = 1 - 1.0e-6f;
04816     double r11, r12, r13, r23, r31, r32, r33;
04817     c = 0;
04818     for (l=0; l<n_lines; ++l){
04819         c = 2*l;
04820         if (seq[c]!=mem){
04821             mem = seq[c];
04822             a = seq[c]*9;
04823         }
04824         b = seq[c+1]*9;
04825 
04826         // this is equivalent to R = A*B'
04827         r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2];
04828         r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5];
04829         r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8];
04830         r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8];
04831         r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2];
04832         r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5];
04833         r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8];
04834         if (r33 > vmax) {
04835             n2 = 270;
04836             n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11)));
04837         }
04838         else if (r33 < -vmax) {
04839             n2 = 270;
04840             n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11)));
04841         } else {
04842             n2 = nint180((float)(rad_deg*atan2(r31, -r32)));
04843             n1 = nint180((float)(rad_deg*atan2(r13, r23)));
04844             if (n1 < 0) {n1 += 360;}
04845             if (n2 <= 0) {n2 = abs(n2);}
04846             else {n2 = 360 - n2;}
04847         }
04848         if (n1 >= 360){n1 = n1 % 360;}
04849         if (n2 >= 360){n2 = n2 % 360;}
04850 
04851         // store common-lines
04852         com[c] = n1;
04853         com[c+1] = n2;
04854     }
04855 
04856     return com;
04857 
04858 }

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

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

04674                                                                                                   {
04675     int j;
04676     int nx = sino->get_xsize();
04677     int i = nx * pos_line;
04678     float r1, r2;
04679     float *line_ptr = line->get_data();
04680     float *sino_ptr = sino->get_data();
04681     for (j=ilf;j<=ihf; j += 2) {
04682         r1 = line_ptr[j];
04683         r2 = line_ptr[j + 1];
04684         sino_ptr[i + j - ilf] = r1;
04685         sino_ptr[i + j - ilf + 1] = r2;
04686         sino_ptr[i + nx * nblines + j - ilf] = r1;
04687         sino_ptr[i + nx * nblines + j - ilf + 1] = -r2;
04688     }
04689     sino->update();
04690 }

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

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

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

Definition at line 4937 of file util_sparx.cpp.

04938                                                                                            {
04939     // res: [best_disc, best_ipsi]
04940     // seq: pairwise indexes ij, 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3
04941     // iw : index to know where is the weight for the common-lines on the current projection in the all weights, [12, 4, 2, 7]
04942     vector<double> res(2);
04943     int lnlen = data[0]->get_xsize();
04944     int end = 2*(n_prj-1);
04945     double disc, buf, bdisc, tmp;
04946     int n, i, ipsi, ind, bipsi, c;
04947     float* line_1;
04948     float* line_2;
04949     bdisc = 1.0e6;
04950     bipsi = -1;
04951     // loop psi
04952     for(ipsi=0; ipsi<n_psi; ipsi += d_psi) {
04953         // discrepancy
04954         disc = 0;
04955         c = 0;
04956         for (n=0; n<n_prj; ++n) {
04957             if(n!=iprj) {
04958                 ind = 2*c;
04959                 line_1 = data[iprj]->get_data() + com[ind] * lnlen;
04960                 line_2 = data[n]->get_data() + com[ind+1] * lnlen;
04961                 buf = 0;
04962                 for (i=0; i<lnlen; ++i) {
04963                     tmp = line_1[i]-line_2[i];
04964                     buf += tmp*tmp;
04965                 }
04966                 disc += buf * weights[iw[c]];
04967                 ++c;
04968             }
04969         }
04970         // select the best value
04971         if (disc <= bdisc) {
04972             bdisc = disc;
04973             bipsi = ipsi;
04974         }
04975         // update common-lines
04976         for (i=0; i<end; i+=2){
04977             com[i] += d_psi;
04978             if (com[i] >= n_psi) {com[i] = com[i] % n_psi;}
04979         }
04980     }
04981     res[0] = bdisc;
04982     res[1] = float(bipsi);
04983 
04984     return res;
04985 }

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

References deg_rad.

04730                                                                                              {
04731     float ph, ps;
04732     double cph, cth, cps, sph, sth, sps;
04733     int ind = iprj*9;
04734     // spider convention phi=psi-90, psi=phi+90
04735     ph = nps-90;
04736     ps = nph+90;
04737     ph *= deg_rad;
04738     th *= deg_rad;
04739     ps *= deg_rad;
04740     // pre-calculate some trigo stuffs
04741     cph = cos(ph);
04742     cth = cos(th);
04743     cps = cos(ps);
04744     sph = sin(ph);
04745     sth = sin(th);
04746     sps = sin(ps);
04747     // fill rotation matrix
04748     Rot[ind] = (float)(cph*cps-cth*sps*sph);
04749     Rot[ind+1] = (float)(cph*sps+cth*cps*sph);
04750     Rot[ind+2] = (float)(sth*sph);
04751     Rot[ind+3] = (float)(-sph*cps-cth*sps*cph);
04752     Rot[ind+4] = (float)(-sph*sps+cth*cps*cph);
04753     Rot[ind+5] = (float)(sth*cph);
04754     Rot[ind+6] = (float)(sth*sps);
04755     Rot[ind+7] = (float)(-sth*cps);
04756     Rot[ind+8] = (float)(cth);
04757 
04758     return Rot;
04759 }

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

Definition at line 4584 of file util_sparx.cpp.

References Assert, PI2, and vrdg().

04584                                                         {
04585         static const int NBIN = 100;
04586         int nline=cml.size()/2;
04587         vector<double> weights(nline);
04588 
04589         vector<ori_t> angs(nline);
04590         for( int i=0; i < nline; ++i ) {
04591                 angs[i].iphi = int( NBIN*cml[2*i] );
04592                 angs[i].itht = int( NBIN*cml[2*i+1] );
04593                 if( angs[i].itht == 180*NBIN ) angs[i].itht = 0;
04594                 angs[i].id = i;
04595         }
04596 
04597         //std::cout << "# of angs: " << angs.size() << std::endl;
04598 
04599         std::sort( angs.begin(), angs.end(), cmpang() );
04600 
04601         vector<float> newphi;
04602         vector<float> newtht;
04603         vector< vector<int> > indices;
04604 
04605         int curt_iphi = -1;
04606         int curt_itht = -1;
04607         for(unsigned int i=0 ;i < angs.size(); ++i ) {
04608                 if( angs[i].iphi==curt_iphi && angs[i].itht==curt_itht ) {
04609                         Assert( indices.size() > 0 );
04610                         indices.back().push_back(angs[i].id);
04611                 } else {
04612                         curt_iphi = angs[i].iphi;
04613                         curt_itht = angs[i].itht;
04614 
04615                         newphi.push_back( float(curt_iphi)/NBIN );
04616                         newtht.push_back( float(curt_itht)/NBIN );
04617                         indices.push_back( vector<int>(1,angs[i].id) );
04618                 }
04619         }
04620 
04621         //std::cout << "# of indpendent ang: " << newphi.size() << std::endl;
04622 
04623 
04624         int num_agl = newphi.size();
04625 
04626         if(num_agl>2) {
04627                 vector<double> w=Util::vrdg(newphi, newtht);
04628 
04629                 Assert( w.size()==newphi.size() );
04630                 Assert( indices.size()==newphi.size() );
04631 
04632                 for(unsigned int i=0; i < newphi.size(); ++i ) {
04633                     /*
04634                     std::cout << "phi,tht,w,n: ";
04635                     std::cout << boost::format( "%10.3f" ) % newphi[i] << " ";
04636                     std::cout << boost::format( "%10.3f" ) % newtht[i] << " ";
04637                     std::cout << boost::format( "%8.6f"  ) % w[i] << " ";
04638                     std::cout << indices[i].size() << "(";
04639                     */
04640 
04641                     for(unsigned int j=0; j < indices[i].size(); ++j ) {
04642                             int id = indices[i][j];
04643                             weights[id] = w[i]/indices[i].size();
04644                             //std::cout << id << " ";
04645                     }
04646 
04647                     //std::cout << ")" << std::endl;
04648 
04649                 }
04650         } else {
04651                 cout<<"warning in Util.cml_weights"<<endl;
04652                 double val = PI2/float(nline);
04653                 for(int i=0; i<nline; i++)  weights[i]=val;
04654         }
04655 
04656         return weights;
04657 
04658 }

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

Definition at line 7154 of file util_sparx.cpp.

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

Referenced by hsortd().

07155 {
07156         return(tmp1.theta1 < tmp2.theta1);
07157 }

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

Definition at line 7159 of file util_sparx.cpp.

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

Referenced by hsortd().

07160 {
07161         return(tmp1.key1 < tmp2.key1);
07162 }

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

Definition at line 5345 of file util_sparx.cpp.

Referenced by cyclicshift(), and slicereverse().

05345                                                     {
05346         float* tmp = new float[nx];
05347         int n = (end - beg)/nx;
05348         int nhalf = n/2;
05349         for (int i = 0; i < nhalf; i++) {
05350                 // swap col i and col n-1-i
05351                 memcpy(tmp, beg+i*nx, nx*sizeof(float));
05352                 memcpy(beg+i*nx, beg+(n-1-i)*nx, nx*sizeof(float));
05353                 memcpy(beg+(n-1-i)*nx, tmp, nx*sizeof(float));
05354         }
05355         delete[] tmp;
05356 }

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

Definition at line 6037 of file util_sparx.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, img_ptr, new_ptr, nx, ny, and EMAN::EMData::set_size().

Referenced by EMAN::PCA::dopca(), and EMAN::PCA::dopca_lan().

06038 {
06039         /***********
06040         ***get the size of the image for validation purpose
06041         **************/
06042         int nx = image->get_xsize(),ny = image->get_ysize(),nz = image->get_zsize();  //Aren't  these  implied?  Please check and let me know, PAP.
06043         /********
06044         ***Exception Handle
06045         *************/
06046         if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize())
06047                 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!");
06048 
06049         size_t i, size = (size_t)nx*ny*nz;
06050 
06051         float* img_ptr = image->get_data();
06052         float* mask_ptr = mask->get_data();
06053 
06054         int ln=0;  //length of the output image = number of points under the mask.
06055         for(i = 0;i < size;i++) if(mask_ptr[i] > 0.5f) ln++;
06056 
06057         EMData* new_image = new EMData();
06058         new_image->set_size(ln,1,1); /* set size of the new image */
06059         float *new_ptr    = new_image->get_data();
06060 
06061         ln=-1;
06062         for(i = 0;i < size;i++){
06063                 if(mask_ptr[i] > 0.5f) {
06064                         ln++;
06065                         new_ptr[ln]=img_ptr[i];
06066                 }
06067         }
06068 
06069         return new_image;
06070 }

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

References ENTERFUNC, EXITFUNC, and ssyev_().

06167 {
06168         // n size of the covariance/correlation matrix
06169         // covmat --- covariance/correlation matrix (n by n)
06170         // eigval --- returns eigenvalues
06171         // eigvec --- returns eigenvectors
06172 
06173         ENTERFUNC;
06174 
06175         int i;
06176 
06177         // make a copy of covmat so that it will not be overwritten
06178         for ( i = 0 ; i < n * n ; i++ )   eigvec[i] = covmat[i];
06179 
06180         char NEEDV = 'V';
06181         char UPLO = 'U';
06182         int lwork = -1;
06183         int info = 0;
06184         float *work, wsize;
06185 
06186         //  query to get optimal workspace
06187         ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, &wsize, &lwork, &info);
06188         lwork = (int)wsize;
06189 
06190         work = (float *)calloc(lwork, sizeof(float));
06191         //  calculate eigs
06192         ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, work, &lwork, &info);
06193         free(work);
06194         EXITFUNC;
06195         return info;
06196 }

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

References coveig(), covmat, eigval, eigvec, ENTERFUNC, EXITFUNC, and status.

06199 {
06200 
06201         ENTERFUNC;
06202         int len = covmatpy.size();
06203         float *eigvec;
06204         float *eigval;
06205         float *covmat;
06206         int status = 0;
06207         eigval = (float*)calloc(ncov,sizeof(float));
06208         eigvec = (float*)calloc(ncov*ncov,sizeof(float));
06209         covmat = (float*)calloc(ncov*ncov, sizeof(float));
06210 
06211         const float *covmat_ptr;
06212         covmat_ptr = &covmatpy[0];
06213         for(int i=0;i<len;i++){
06214             covmat[i] = covmat_ptr[i];
06215         }
06216 
06217         status = Util::coveig(ncov, covmat, eigval, eigvec);
06218 
06219         vector<float> eigval_py(ncov);
06220         const float *eigval_ptr;
06221         eigval_ptr = &eigval[0];
06222         for(int i=0;i<ncov;i++){
06223             eigval_py[i] = eigval_ptr[i];
06224         }
06225 
06226         vector<float> eigvec_py(ncov*ncov);
06227         const float *eigvec_ptr;
06228         eigvec_ptr = &eigvec[0];
06229         for(int i=0;i<ncov*ncov;i++){
06230             eigvec_py[i] = eigvec_ptr[i];
06231         }
06232 
06233         Dict res;
06234         res["eigval"] = eigval_py;
06235         res["eigvec"] = eigvec_py;
06236 
06237         EXITFUNC;
06238         return res;
06239 }

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, EMAN::Dict::size(), 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 4077 of file util_sparx.cpp.

References circ1, circ1b, circ2, circ2b, dout, fftr_d(), EMAN::EMData::get_data(), log(), numr, q, EMAN::EMData::set_size(), and t.

04077                                                                         {
04078 
04079    // dimension         circ1(lcirc),circ2(lcirc)
04080 
04081         int   ip, jc, numr3i, numr2i, i, j;
04082         float t1, t2, t3, t4, c1, c2, d1, d2;
04083 
04084         int nring = numr.size()/3;
04085         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
04086         int maxrin = numr[numr.size()-1];
04087 
04088         float* circ1b = circ1->get_data();
04089         float* circ2b = circ2->get_data();
04090 
04091         // t(maxrin), q(maxrin)  // removed +2
04092         double *t, *q;
04093 
04094         q = (double*)calloc(maxrin,sizeof(double));
04095         t = (double*)calloc(maxrin,sizeof(double));
04096 
04097 #ifdef _WIN32
04098         ip = -(int)(log((float)maxrin)/log(2.0f));
04099 #else
04100         ip = -(int)(log2(maxrin));
04101 #endif  //_WIN32
04102 
04103         //  q - straight  = circ1 * conjg(circ2)
04104 
04105         //   t - mirrored  = conjg(circ1) * conjg(circ2)
04106 
04107         //   premultiply  arrays ie( circ12 = circ1 * circ2) much slower
04108 
04109         for (i=1; i<=nring; i++) {
04110 
04111                 numr3i = numr(3,i);
04112                 numr2i = numr(2,i);
04113 
04114                 t1   = circ1b(numr2i) * circ2b(numr2i);
04115                 q(1) = q(1)+t1;
04116                 t(1) = t(1)+t1;
04117 
04118                 t1   = circ1b(numr2i+1) * circ2b(numr2i+1);
04119                 if (numr3i == maxrin)  {
04120                         q(2) += t1;
04121                         t(2) += t1;
04122                 } else {
04123                         q(numr3i+1) += t1;
04124                         t(numr3i+1) += t1;
04125                 }
04126 
04127                 for (j=3; j<=numr3i; j=j+2) {
04128                         jc     = j+numr2i-1;
04129 
04130                         c1     = circ1b(jc);
04131                         c2     = circ1b(jc+1);
04132                         d1     = circ2b(jc);
04133                         d2     = circ2b(jc+1);
04134 
04135                         t1     = c1 * d1;
04136                         t3     = c1 * d2;
04137                         t2     = c2 * d2;
04138                         t4     = c2 * d1;
04139 
04140                         q(j)   += t1 + t2;
04141                         q(j+1) += - t3 + t4;
04142                         t(j)   += t1 - t2;
04143                         t(j+1) += - t3 - t4;
04144                 }
04145         }
04146 
04147         // straight
04148         fftr_d(q,ip);
04149 
04150         // mirrored
04151         fftr_d(t,ip);
04152 
04153         EMData* out = new EMData();
04154         out->set_size(maxrin,2,1);
04155         float *dout = out->get_data();
04156         for (int i=0; i<maxrin; i++) {dout(i,0)=static_cast<float>(q[i]); dout(i,1)=static_cast<float>(t[i]);}
04157         //out->set_size(maxrin,1,1);
04158         //float *dout = out->get_data();
04159         //for (int i=0; i<maxrin; i++) {dout(i,0)=q[i];}
04160         free(t);
04161         free(q);
04162         return out;
04163 }

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

References circ1, circ1b, circ2, circ2b, dout, fftr_d(), EMAN::EMData::get_data(), log(), numr, EMAN::EMData::set_size(), and t.

04325 {
04326 
04327         int   ip, jc, numr3i, numr2i, i, j;
04328         float t1, t2, t3, t4, c1, c2, d1, d2;
04329 
04330         int nring = numr.size()/3;
04331         int maxrin = numr[numr.size()-1];
04332 
04333         float* circ1b = circ1->get_data();
04334         float* circ2b = circ2->get_data();
04335 
04336         double *t;
04337 
04338         t = (double*)calloc(maxrin,sizeof(double));
04339 
04340 #ifdef _WIN32
04341         ip = -(int)(log((float)maxrin)/log(2.0f));
04342 #else
04343         ip = -(int)(log2(maxrin));
04344 #endif  //_WIN32
04345 
04346          //   t - mirrored  = conjg(circ1) * conjg(circ2)
04347 
04348         for (i=1;i<=nring;i++) {
04349 
04350                 numr3i = numr(3,i);
04351                 numr2i = numr(2,i);
04352 
04353                 t1   = circ1b(numr2i) * circ2b(numr2i);
04354                 t(1) = t(1)+t1;
04355 
04356                 if (numr3i == maxrin)  {
04357                         t1   = circ1b(numr2i+1) * circ2b(numr2i+1);
04358                         t(2) = t(2)+t1;
04359                 }
04360 
04361                 for (j=3;j<=numr3i;j=j+2) {
04362                         jc     = j+numr2i-1;
04363 
04364                         c1     = circ1b(jc);
04365                         c2     = circ1b(jc+1);
04366                         d1     = circ2b(jc);
04367                         d2     = circ2b(jc+1);
04368 
04369                         t1     = c1 * d1;
04370                         t3     = c1 * d2;
04371                         t2     = c2 * d2;
04372                         t4     = c2 * d1;
04373 
04374                         t(j)   = t(j)   + t1 - t2;
04375                         t(j+1) = t(j+1) - t3 - t4;
04376                 }
04377         }
04378 
04379         // mirrored
04380         fftr_d(t,ip);
04381 
04382         EMData* out = new EMData();
04383         out->set_size(maxrin,1,1);
04384         float *dout = out->get_data();
04385         for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(t[i]);
04386         free(t);
04387         return out;
04388 
04389 }

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

References circ1, circ1b, circ2, circ2b, dout, fftr_d(), EMAN::EMData::get_data(), log(), numr, q, and EMAN::EMData::set_size().

04254 {
04255 
04256         int   ip, jc, numr3i, numr2i, i, j;
04257         float t1, t2, t3, t4, c1, c2, d1, d2;
04258 
04259         int nring = numr.size()/3;
04260         int maxrin = numr[numr.size()-1];
04261 
04262         float* circ1b = circ1->get_data();
04263         float* circ2b = circ2->get_data();
04264 
04265         double *q;
04266 
04267         q = (double*)calloc(maxrin,sizeof(double));
04268 
04269 #ifdef _WIN32
04270         ip = -(int)(log((float)maxrin)/log(2.0f));
04271 #else
04272         ip = -(int)(log2(maxrin));
04273 #endif  //_WIN32
04274 
04275          //  q - straight  = circ1 * conjg(circ2)
04276 
04277         for (i=1;i<=nring;i++) {
04278 
04279                 numr3i = numr(3,i);
04280                 numr2i = numr(2,i);
04281 
04282                 t1   = circ1b(numr2i) * circ2b(numr2i);
04283                 q(1) = q(1)+t1;
04284 
04285                 if (numr3i == maxrin)  {
04286                         t1   = circ1b(numr2i+1) * circ2b(numr2i+1);
04287                         q(2) = q(2)+t1;
04288                 } else {
04289                         t1              = circ1b(numr2i+1) * circ2b(numr2i+1);
04290                         q(numr3i+1) = q(numr3i+1)+t1;
04291                 }
04292 
04293                 for (j=3;j<=numr3i;j=j+2) {
04294                         jc     = j+numr2i-1;
04295 
04296                         c1     = circ1b(jc);
04297                         c2     = circ1b(jc+1);
04298                         d1     = circ2b(jc);
04299                         d2     = circ2b(jc+1);
04300 
04301                         t1     = c1 * d1;
04302                         t3     = c1 * d2;
04303                         t2     = c2 * d2;
04304                         t4     = c2 * d1;
04305 
04306                         q(j)   = q(j)   + t1 + t2;
04307                         q(j+1) = q(j+1) - t3 + t4;
04308                 }
04309         }
04310 
04311         // straight
04312         fftr_d(q,ip);
04313 
04314         EMData* out = new EMData();
04315         out->set_size(maxrin,1,1);
04316         float *dout = out->get_data();
04317         for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(q[i]);
04318         free(q);
04319         return out;
04320 
04321 }

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

References circ1, circ1b, circ2, circ2b, fftr_q(), log(), numr, q, and t.

Referenced by ali2d_ccf_list(), Crosrng_msg_vec_p(), multiref_peaks_ali2d(), and multiref_peaks_compress_ali2d().

04181                                                                                              {
04182 
04183    // dimension         circ1(lcirc),circ2(lcirc)
04184 
04185         int   ip, jc, numr3i, numr2i, i, j;
04186         float t1, t2, t3, t4, c1, c2, d1, d2;
04187 
04188         int nring = numr.size()/3;
04189         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
04190         int maxrin = numr[numr.size()-1];
04191 
04192         float* circ1b = circ1->get_data();
04193         float* circ2b = circ2->get_data();
04194 
04195 #ifdef _WIN32
04196         ip = -(int)(log((float)maxrin)/log(2.0f));
04197 #else
04198         ip = -(int)(log2(maxrin));
04199 #endif  //_WIN32
04200         for (int i=1; i<=maxrin; i++)  {q(i) = 0.0f; t(i) = 0.0f;}
04201 
04202         //  q - straight  = circ1 * conjg(circ2)
04203 
04204         //   t - mirrored  = conjg(circ1) * conjg(circ2)
04205 
04206         for (i=1; i<=nring; i++) {
04207 
04208                 numr3i = numr(3,i);
04209                 numr2i = numr(2,i);
04210 
04211                 t1   = circ1b(numr2i) * circ2b(numr2i);
04212                 q(1) += t1;
04213                 t(1) += t1;
04214 
04215                 t1   = circ1b(numr2i+1) * circ2b(numr2i+1);
04216                 if (numr3i == maxrin)  {
04217                         q(2) += t1;
04218                         t(2) += t1;
04219                 } else {
04220                         q(numr3i+1) += t1;
04221                         t(numr3i+1) += t1;
04222                 }
04223 
04224                 for (j=3; j<=numr3i; j=j+2) {
04225                         jc     = j+numr2i-1;
04226 
04227                         c1     = circ1b(jc);
04228                         c2     = circ1b(jc+1);
04229                         d1     = circ2b(jc);
04230                         d2     = circ2b(jc+1);
04231 
04232                         t1     = c1 * d1;
04233                         t3     = c1 * d2;
04234                         t2     = c2 * d2;
04235                         t4     = c2 * d1;
04236 
04237                         q(j)   += t1 + t2;
04238                         q(j+1) += -t3 + t4;
04239                         t(j)   += t1 - t2;
04240                         t(j+1) += -t3 - t4;
04241                 }
04242         }
04243         // straight
04244         fftr_q(q,ip);
04245         //for (int i=0; i<maxrin; i++) cout<<i<<"  B    "<<q[i]<<"       "<<t[i]<<endl;
04246 
04247         // mirrored
04248         fftr_q(t,ip);
04249 }

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

Definition at line 4166 of file util_sparx.cpp.

References circ1, circ2, and Crosrng_msg_vec().

04166                                                                                      {
04167 
04168         int maxrin = numr[numr.size()-1];
04169 
04170         vector<float> r(2*maxrin);
04171 
04172         Crosrng_msg_vec( circ1, circ2, numr, &r[0], &r[maxrin] );
04173 
04174         return r;
04175 }

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

Definition at line 3978 of file util_sparx.cpp.

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

Referenced by multiref_polar_ali_2d_nom().

03978                                                                       {
03979         int nring = numr.size()/3;
03980         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03981         int maxrin = numr[numr.size()-1];
03982         double qn; float tot;
03983         float *circ1 = circ1p->get_data();
03984         float *circ2 = circ2p->get_data();
03985 /*
03986 c
03987 c  checks only straight position
03988 c
03989 c  input - fourier transforms of rings!!
03990 c  circ1 already multiplied by weights!
03991 c
03992 */
03993 
03994         // dimension             circ1(lcirc),circ2(lcirc)
03995 
03996         // q(maxrin), t7(-3:3)  //maxrin+2 removed
03997         double *q, t7[7];
03998 
03999         int   ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
04000         float c1, c2, d1, d2, pos;
04001 
04002         qn  = 0.0;
04003         tot = 0.0;
04004 #ifdef _WIN32
04005         ip = -(int)(log((float)maxrin)/log(2.0f));
04006 #else
04007    ip = -(int)(log2(maxrin));
04008 #endif  //_WIN32
04009         //for (j=1; j<=maxrin;j++) cout <<"  "<<j<<"   "<<circ1(j)<<"   "<<circ2(j) <<endl;
04010 
04011         //  c - straight  = circ1 * conjg(circ2)
04012         //  zero q array
04013 
04014         q = (double*)calloc(maxrin,sizeof(double));
04015 
04016                         //   premultiply  arrays ie( circ12 = circ1 * circ2) much slower
04017         for (i=1; i<=nring; i++) {
04018 
04019                 numr3i = numr(3,i);   // Number of samples of this ring
04020                 numr2i = numr(2,i);   // The beginning point of this ring
04021 
04022                 q(1) += circ1(numr2i) * circ2(numr2i);
04023 
04024                 if (numr3i == maxrin)   q(2) += circ1(numr2i+1) * circ2(numr2i+1);
04025                 else  q(numr3i+1) += circ1(numr2i+1) * circ2(numr2i+1);
04026 
04027                 for (j=3; j<=numr3i; j += 2) {
04028                         jc     = j+numr2i-1;
04029 
04030 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
04031 //                                ----- -----    ----- -----
04032 //                                 t1     t2      t3    t4
04033 
04034                         c1     = circ1(jc);
04035                         c2     = circ1(jc+1);
04036                         d1     = circ2(jc);
04037                         d2     = circ2(jc+1);
04038 
04039                         q(j)   += c1 * d1 + c2 * d2;
04040                         q(j+1) += -c1 * d2 + c2 * d1;
04041                 }
04042         }
04043 //for (j=1; j<=maxrin; j++) cout <<"  "<<j<<"   "<<q(j) <<endl;
04044         fftr_d(q,ip);
04045 
04046         qn  = -1.0e20;
04047         for (j=1; j<=maxrin; j++) {//cout <<"  "<<j<<"   "<<q(j) <<endl;
04048                 if (q(j) >= qn) {
04049                         qn  = q(j);
04050                         jtot = j;
04051                 }
04052         }
04053 
04054         for (k=-3; k<=3; k++)  {
04055                 j = ((jtot+k+maxrin-1)%maxrin)+1;
04056                 t7(k+4) = q(j);
04057         }
04058 
04059         // interpolate
04060         prb1d(t7,7,&pos);
04061         tot = (float)(jtot)+pos;
04062         // Do not interpolate
04063         //*tot = (float)(jtot);
04064 
04065         free(q);
04066 
04067         Dict retvals;
04068         retvals["qn"] = qn;
04069         retvals["tot"] = tot;
04070         return retvals;
04071 }

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

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

Referenced by multiref_polar_ali_2d_local_psi().

03844                                                                                                {
03845 // flag 0 - straignt, 1 - mirror
03846 
03847         int nring = numr.size()/3;
03848         int maxrin = numr[numr.size()-1];
03849         double qn; float tot; double qm; float tmt;
03850         float *circ1 = circ1p->get_data();
03851         float *circ2 = circ2p->get_data();
03852 
03853         double *q, t7[7];
03854 
03855         int   ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
03856         float t1, t2, t3, t4, c1, c2, d1, d2, pos;
03857 
03858         qn  = 0.0f;
03859         qm  = 0.0f;
03860         tot = 0.0f;
03861         tmt = 0.0f;
03862 #ifdef _WIN32
03863         ip = -(int)(log((float)maxrin)/log(2.0f));
03864 #else
03865         ip = -(int)(log2(maxrin));
03866 #endif  //_WIN32
03867 
03868         //  c - straight  = circ1 * conjg(circ2)
03869         //  zero q array
03870 
03871         q = (double*)calloc(maxrin,sizeof(double));
03872 
03873    //   premultiply  arrays ie( circ12 = circ1 * circ2) much slower
03874         if (flag==0) {
03875                 for (i=1; i<=nring; i++) {
03876 
03877                         numr3i = numr(3,i);   // Number of samples of this ring
03878                         numr2i = numr(2,i);   // The beginning point of this ring
03879 
03880                         t1   = circ1(numr2i) * circ2(numr2i);
03881                         q(1) += t1;
03882 
03883                         t1   = circ1(numr2i+1) * circ2(numr2i+1);
03884                         if (numr3i == maxrin)  {
03885                                 q(2) += t1;
03886                         } else {
03887                                 q(numr3i+1) += t1;
03888                         }
03889 
03890                         for (j=3; j<=numr3i; j += 2) {
03891                                 jc     = j+numr2i-1;
03892 
03893         // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03894         //                                ----- -----    ----- -----
03895         //                                 t1     t2      t3    t4
03896 
03897                                 c1     = circ1(jc);
03898                                 c2     = circ1(jc+1);
03899                                 d1     = circ2(jc);
03900                                 d2     = circ2(jc+1);
03901 
03902                                 t1     = c1 * d1;
03903                                 t3     = c1 * d2;
03904                                 t2     = c2 * d2;
03905                                 t4     = c2 * d1;
03906 
03907                                 q(j)   += t1 + t2;
03908                                 q(j+1) += -t3 + t4;
03909                         }
03910                 }
03911         } else {
03912                 for (i=1; i<=nring; i++) {
03913 
03914                         numr3i = numr(3,i);   // Number of samples of this ring
03915                         numr2i = numr(2,i);   // The beginning point of this ring
03916 
03917                         t1   = circ1(numr2i) * circ2(numr2i);
03918                         q(1) += t1;
03919 
03920                         t1   = circ1(numr2i+1) * circ2(numr2i+1);
03921                         if (numr3i == maxrin)  {
03922                                 q(2) += t1;
03923                         } else {
03924                                 q(numr3i+1) += t1;
03925                         }
03926 
03927                         for (j=3; j<=numr3i; j += 2) {
03928                                 jc     = j+numr2i-1;
03929 
03930         // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03931         //                                ----- -----    ----- -----
03932         //                                 t1     t2      t3    t4
03933 
03934                                 c1     = circ1(jc);
03935                                 c2     = circ1(jc+1);
03936                                 d1     = circ2(jc);
03937                                 d2     = circ2(jc+1);
03938 
03939                                 t1     = c1 * d1;
03940                                 t3     = c1 * d2;
03941                                 t2     = c2 * d2;
03942                                 t4     = c2 * d1;
03943 
03944                                 q(j)   += t1 - t2;
03945                                 q(j+1) += -t3 - t4;
03946                         }
03947                 }
03948         }
03949         fftr_d(q,ip);
03950 
03951         qn  = -1.0e20;
03952         int psi_pos = int(psi/360.0*maxrin+0.5);
03953 
03954         for (k=-5; k<=5; k++) {
03955                 j = (psi_pos+maxrin-1)%maxrin+1;
03956                 if (q(j) >= qn) {
03957                         qn  = q(j);
03958                         jtot = j;
03959                 }
03960         }
03961 
03962         for (k=-3; k<=3; k++) {
03963                 j = ((jtot+k+maxrin-1)%maxrin)+1;
03964                 t7(k+4) = q(j);
03965         }
03966 
03967         // interpolate
03968         prb1d(t7,7,&pos);
03969         tot = (float)(jtot)+pos;
03970         free(q);
03971 
03972         Dict retvals;
03973         retvals["qn"] = qn;
03974         retvals["tot"] = tot;
03975         return retvals;
03976 }

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

References EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), tf(), and EMAN::EMData::update().

19575 {
19576         int   ix, iy, iz;
19577         int   i,  j, k;
19578         int   nr2, nl2;
19579         float  dzz, az, ak;
19580         float  scx, scy, scz;
19581         int offset = 2 - nx%2;
19582         int lsm = nx + offset;
19583         EMData* ctf_img1 = new EMData();
19584         ctf_img1->set_size(lsm, ny, nz);
19585         float freq = 1.0f/(2.0f*ps);
19586         scx = 2.0f/float(nx);
19587         if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f;
19588         if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f;
19589         nr2 = ny/2 ;
19590         nl2 = nz/2 ;
19591         for ( k=0; k<nz;k++) {
19592                 iz = k;  if(k>nl2) iz=k-nz;
19593                 for ( j=0; j<ny;j++) {
19594                         iy = j;  if(j>nr2) iy=j - ny;
19595                         for ( i=0; i<lsm/2; i++) {
19596                                 ix=i;
19597                                 ak=pow(ix*ix*scx*scx+iy*scy*iy*scy+iz*scz*iz*scz, 0.5f)*freq;
19598                                 if(ak!=0) az=0.0; else az=M_PI;
19599                                 dzz = dz + dza/2.0f*sin(2*(az-azz*M_PI/180.0f));
19600                                 (*ctf_img1) (i*2,j,k)   = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign);
19601                                 (*ctf_img1) (i*2+1,j,k) = 0.0f;
19602                         }
19603                 }
19604         }
19605         ctf_img1->update();
19606         ctf_img1->set_complex(true);
19607         ctf_img1->set_ri(true);
19608         //ctf_img1->attr_dict["is_complex"] = 1;
19609         //ctf_img1->attr_dict["is_ri"] = 1;
19610         if(nx%2==0) ctf_img1->set_fftodd(false); else ctf_img1->set_fftodd(true);
19611         return ctf_img1;
19612 }

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

References colreverse(), data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, EMAN::EMData::is_complex(), nx, ny, slicereverse(), and EMAN::EMData::update().

05365                                                  {
05366 
05367         if (image->is_complex()) throw ImageFormatException("Real image required for IntegerCyclicShift2DProcessor");
05368 
05369         int dx = params["dx"];
05370         int dy = params["dy"];
05371         int dz = params["dz"];
05372 
05373         // The reverse trick we're using shifts to the left (a negative shift)
05374         int nx = image->get_xsize();
05375         dx %= nx;
05376         if (dx < 0) dx += nx;
05377         int ny = image->get_ysize();
05378         dy %= ny;
05379         if (dy < 0) dy += ny;
05380         int nz = image->get_zsize();
05381         dz %= nz;
05382         if (dz < 0) dz += nz;
05383 
05384         int mx = -(dx - nx);
05385         int my = -(dy - ny);
05386         int mz = -(dz - nz);
05387 
05388         float* data = image->get_data();
05389         // x-reverses
05390         if (mx != 0) {
05391                 for (int iz = 0; iz < nz; iz++)
05392                        for (int iy = 0; iy < ny; iy++) {
05393                                 // reverses for column iy
05394                                 size_t offset = nx*iy + (size_t)nx*ny*iz; // starting location for column iy in slice iz
05395                                 reverse(&data[offset],&data[offset+mx]);
05396                                 reverse(&data[offset+mx],&data[offset+nx]);
05397                                 reverse(&data[offset],&data[offset+nx]);
05398                         }
05399         }
05400         // y-reverses
05401         if (my != 0) {
05402                 for (int iz = 0; iz < nz; iz++) {
05403                         size_t offset = (size_t)nx*ny*iz;
05404                         colreverse(&data[offset], &data[offset + my*nx], nx);
05405                         colreverse(&data[offset + my*nx], &data[offset + ny*nx], nx);
05406                         colreverse(&data[offset], &data[offset + ny*nx], nx);
05407                 }
05408         }
05409         if (mz != 0) {
05410                 slicereverse(&data[0], &data[(size_t)mz*ny*nx], nx, ny);
05411                 slicereverse(&data[mz*ny*nx], &data[(size_t)nz*ny*nx], nx, ny);
05412                 slicereverse(&data[0], &data[(size_t)nz*ny*nx], nx ,ny);
05413         }
05414         image->update();
05415 }

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

Definition at line 5159 of file util_sparx.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, LOGERR, new_ptr, NullPointerException, nx, ny, old_ptr, EMAN::EMData::set_size(), and EMAN::EMData::update().

05160 {
05161         /* Exception Handle */
05162         if (!img) {
05163                 throw NullPointerException("NULL input image");
05164         }
05165         /* ============================== */
05166 
05167         // Get the size of the input image
05168         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
05169         /* ============================== */
05170 
05171 
05172         /* Exception Handle */
05173         if ((x_step-1 > nx/2 || y_step-1 > ny/2 || z_step-1 > nz/2) || (x_step-1)<0 || (y_step-1)<0 || (z_step-1)<0)
05174         {
05175                 LOGERR("Parameters for decimation cannot exceed the center of the image.");
05176                 throw ImageDimensionException("Parameters for decimation cannot exceed the center of the image.");
05177         }
05178         /* ============================== */
05179 
05180 
05181         /*    Calculation of the start point */
05182         int new_st_x=(nx/2)%x_step, new_st_y=(ny/2)%y_step, new_st_z=(nz/2)%z_step;
05183         /* ============================*/
05184 
05185 
05186         /* Calculation of the size of the decimated image */
05187         int rx=2*(nx/(2*x_step)), ry=2*(ny/(2*y_step)), rz=2*(nz/(2*z_step));
05188         int r1=int(ceil((nx-(x_step*rx))/(1.f*x_step))), r2=int(ceil((ny-(y_step*ry))/(1.f*y_step)));
05189         int r3=int(ceil((nz-(z_step*rz))/(1.f*z_step)));
05190         if(r1>1){r1=1;}
05191         if(r2>1){r2=1;}
05192         if(r3>1){r3=1;}
05193         int new_nx=rx+r1, new_ny=ry+r2, new_nz=rz+r3;
05194         /* ===========================================*/
05195 
05196 
05197         EMData* img2 = new EMData();
05198         img2->set_size(new_nx,new_ny,new_nz);
05199         float *new_ptr = img2->get_data();
05200         float *old_ptr = img->get_data();
05201         int iptr, jptr, kptr = 0;
05202         for (int k=new_st_z; k<nz; k+=z_step) {jptr=0;
05203                 for (int j=new_st_y; j<ny; j+=y_step) {iptr=0;
05204                         for (int i=new_st_x; i<nx; i+=x_step) {
05205                                 new_ptr(iptr,jptr,kptr) = old_ptr(i,j,k);
05206                         iptr++;}
05207                 jptr++;}
05208         kptr++;}
05209         img2->update();
05210         return img2;
05211 }

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

Definition at line 7670 of file util_sparx.cpp.

References ENTERFUNC, and EXITFUNC.

07671 {
07672         ENTERFUNC;
07673         int k, i;
07674         for(i=0; i<len; i++) key[i]=i+1;
07675 
07676         for(i = 0; i<len;i++){
07677                 k = rand()%len;
07678                 std::swap(key[k], key[i]);
07679                 std::swap(x[k], x[i]);
07680                 std::swap(y[k], y[i]);
07681         }
07682         EXITFUNC;
07683 }

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

Definition at line 17629 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update().

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         if(img->is_complex()) {
17643                 for (size_t i=0; i<size; i+=2) {
17644                         if(img1_ptr[i] > 1.e-10f) {
17645                         img_ptr[i]   /= img1_ptr[i];
17646                         img_ptr[i+1] /= img1_ptr[i];
17647                         } else img_ptr[i] = img_ptr[i+1] = 0.0f;
17648                 }
17649         } else throw ImageFormatException("Only Fourier image allowed");
17650 
17651         img->update();
17652 
17653         EXITFUNC;
17654 }

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

Definition at line 17600 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update().

17601 {
17602         ENTERFUNC;
17603         /* Exception Handle */
17604         if (!img) {
17605                 throw NullPointerException("NULL input image");
17606         }
17607         /* ========= img /= img1 ===================== */
17608 
17609         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17610         size_t size = (size_t)nx*ny*nz;
17611         float *img_ptr  = img->get_data();
17612         float *img1_ptr = img1->get_data();
17613         if(img->is_complex()) {
17614                 float  sq2;
17615                 for (size_t i=0; i<size; i+=2) {
17616                         sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i]   + img1_ptr[i+1] * img1_ptr[i+1]);
17617                         float tmp    = sq2*(img_ptr[i] * img1_ptr[i]   + img_ptr[i+1] * img1_ptr[i+1]) ;
17618                         img_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ;
17619                         img_ptr[i]   = tmp;
17620                 }
17621         } else {
17622                 for (size_t i=0; i<size; ++i) img_ptr[i] /= img1_ptr[i];
17623         }
17624         img->update();
17625 
17626         EXITFUNC;
17627 }

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

Definition at line 17425 of file util_sparx.cpp.

References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, img2_ptr, img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update().

17426 {
17427         ENTERFUNC;
17428         /* Exception Handle */
17429         if (!img) {
17430                 throw NullPointerException("NULL input image");
17431         }
17432         /* ========= img /= img1 ===================== */
17433 
17434         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17435         size_t size = (size_t)nx*ny*nz;
17436         EMData * img2 = img->copy_head();
17437         float *img_ptr  =img->get_data();
17438         float *img1_ptr = img1->get_data();
17439         float *img2_ptr = img2->get_data();
17440         if(img->is_complex()) {
17441                 for (size_t i=0; i<size; i+=2) {
17442                         if(img1_ptr[i] > 1.e-10f) {
17443                         img2_ptr[i]   = img_ptr[i]  /img1_ptr[i];
17444                         img2_ptr[i+1] = img_ptr[i+1]/img1_ptr[i];
17445                         } else img2_ptr[i] = img2_ptr[i+1] = 0.0f;
17446                 }
17447         } else  throw ImageFormatException("Only Fourier image allowed");
17448 
17449         img->update();
17450 
17451         EXITFUNC;
17452         return img2;
17453 }

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

Definition at line 17392 of file util_sparx.cpp.

References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update().

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

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

copy sign of a number.

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

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

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

Definition at line 1952 of file util.h.

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

complementary error function.

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

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

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

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

Definition at line 1977 of file util.h.

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

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

Definition at line 4406 of file util_sparx.cpp.

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

Referenced by ener_tot().

04406                                               {
04407         ENTERFUNC;
04408         long double ener,en;
04409 
04410         int nring = numr.size()/3;
04411         float *aveptr = ave->get_data();
04412 
04413         ener = 0.0;
04414         for (int i=1; i<=nring; i++) {
04415                 int numr3i = numr(3,i);
04416                 int np     = numr(2,i)-1;
04417                 float tq = static_cast<float>(PI2*numr(1,i)/numr3i);
04418                 en = tq*(aveptr[np]*aveptr[np]+aveptr[np+1]*aveptr[np+1])*0.5;
04419                 for (int j=np+2; j<np+numr3i-1; j++) en += tq*aveptr[j]*aveptr[j];
04420                 ener += en/numr3i;
04421         }
04422         EXITFUNC;
04423         return static_cast<float>(ener);
04424 }

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

Definition at line 4426 of file util_sparx.cpp.

References ener(), ENTERFUNC, EXITFUNC, get_data(), numr, and PI2.

04426                                                                                      {
04427         ENTERFUNC;
04428         long double ener, en;
04429         float arg, cs, si;
04430 
04431         int nima = data.size();
04432         int nring = numr.size()/3;
04433         int maxrin = numr(3,nring);
04434 
04435         ener = 0.0;
04436         for (int i=1; i<=nring; i++) {
04437                 int numr3i = numr(3,i);
04438                 int np     = numr(2,i)-1;
04439                 float tq = static_cast<float>(PI2*numr(1,i)/numr3i);
04440                 float temp1 = 0.0, temp2 = 0.0;
04441                 for (int kk=0; kk<nima; kk++) {
04442                         float *ptr = data[kk]->get_data();
04443                         temp1 += ptr[np];
04444                         temp2 += static_cast<float>(ptr[np+1]*cos(PI2*(tot[kk]-1.0f)/2.0f*numr3i/maxrin));
04445                 }
04446                 en = tq*(temp1*temp1+temp2*temp2)*0.5;
04447                 for (int j=2; j<numr3i; j+=2) {
04448                         float tempr = 0.0, tempi = 0.0;
04449                         for (int kk=0; kk<nima; kk++) {
04450                                 float *ptr = data[kk]->get_data();
04451                                 arg = static_cast<float>( PI2*(tot[kk]-1.0)*(j/2)/maxrin );
04452                                 cs = cos(arg);
04453                                 si = sin(arg);
04454                                 tempr += ptr[np + j]*cs - ptr[np + j +1]*si;
04455                                 tempi += ptr[np + j]*si + ptr[np + j +1]*cs;
04456                         }
04457                         en += tq*(tempr*tempr+tempi*tempi);
04458                 }
04459                 ener += en/numr3i;
04460         }
04461         EXITFUNC;
04462         return static_cast<float>(ener);
04463 }

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

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

07019 {
07020         int j,d;
07021         EMData * e = new EMData();
07022         float *eptr, *imgptr;
07023         imgptr = img->get_data();
07024         float SSE = 0.f;
07025         for (j = 0 ; j < N ; j++) {
07026                 e->read_image(images,S[j]);
07027                 eptr = e->get_data();
07028                 for (d = 0; d < size; d++) {
07029                         SSE += ((eptr[d] - imgptr[d])*(eptr[d] - imgptr[d]));}
07030                 }
07031         delete e;
07032         return SSE;
07033 }

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

References k_means_cont_table_().

Referenced by initial_prune().

20478                                                                                                                                                                                 {
20479 
20480 
20481         if (size_next <= T) return 0;
20482 
20483         // take the intx of next and cur
20484         int* curintx2(0);
20485         int nintx = Util::k_means_cont_table_(curintx, next+2, curintx2, size_curintx, size_next,0);
20486         if (nintx <= T) return 0;
20487 
20488         int old_depth=depth;
20489         if (depth == partref) depth = depth + 1; // we skip classes in partref
20490         if (depth == (nParts)) { if (old_depth>0) return 1;}
20491 
20492         // have not yet reached a leaf, and current weight is still greather than T, so keep on going.
20493 
20494         curintx2 = new int[nintx]; // put the intersection set in here
20495         Util::k_means_cont_table_(curintx,next+2,curintx2, size_curintx, size_next,1);
20496 
20497         // if (old_depth > 0) {delete[] curintx;} // don't delete when depth == 0 because curintx in that case is a pointer into Parts
20498 
20499         // we now consider each of the classes in partition (depth+1) in turn
20500         bool gt_thresh;
20501         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
20502 
20503         for (int i=0; i < num_classes; i++){
20504                 if (*(Parts[depth][i]+1) < 1) continue; // class is not active so move on
20505                 size_next = (*(dimClasses + depth*K+(*(Parts[depth][i])) ))-2;
20506                 gt_thresh = explore(Parts,dimClasses, nParts, K, T, partref, curintx2,nintx, Parts[depth][i], size_next, depth+1);
20507                 if (gt_thresh) return 1;
20508         }
20509         delete[] curintx2;
20510         return 0;
20511 }

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

References explore2(), and k_means_cont_table_().

20311                                                                                                                                                                                                                    {
20312 
20313 // depth is the level which is going to be explored in the current iteration
20314         int* curintx2(0);
20315         int nintx = size_curintx;
20316         
20317         
20318         // 2. take the intx of next and cur. Prune if <= T
20319         if (depth >0){
20320                 nintx = Util::k_means_cont_table_(curintx,next, curintx2, size_curintx, size_next,0);
20321                 if (nintx <= T) return; //prune!
20322         }
20323 
20324         // 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
20325         if (depth == (nParts-1)) {
20326                 
20327                 int replace = 0;
20328                 int ind_smallest = -1;
20329                 int smallest_cost = -1;
20330                 
20331                 for (int jit = 0; jit < J; jit++){
20332                         if (*(costlist+jit) < nintx){
20333                                 replace = 1;
20334                                 if (ind_smallest == -1) {ind_smallest = jit; smallest_cost = *(costlist+jit);}
20335                                 if (*(costlist+jit) < smallest_cost) {ind_smallest = jit; smallest_cost = *(costlist+jit);}
20336                         }       
20337                 }
20338                 
20339                 if (replace > 0){
20340                         // replace the smallest cost in matchlist with the current stuff
20341                         *(costlist + ind_smallest) = nintx;
20342                         for (int xit = 0; xit < nParts; xit++)
20343                                 *(matchlist + ind_smallest*nParts + xit) = *(curbranch+xit);
20344                                 
20345                 }
20346                 
20347                 return; 
20348         }
20349         
20350 
20351         // 3. have not yet reached a leaf, and current weight is still greather than T, so keep on going.
20352 
20353         if (depth > 0){
20354                 curintx2 = new int[nintx]; // put the intersection set in here
20355                 Util::k_means_cont_table_(curintx,next,curintx2, size_curintx, size_next,1);
20356         }
20357 
20358         if (depth == 0){
20359                 // set curintx2 to curintx
20360                 curintx2 = new int[size_curintx];
20361                 for (int cp = 0; cp < size_curintx; cp++) *(curintx2+cp) = *(curintx+cp);
20362         }
20363 
20364 
20365         // recursion (non-leaf case)
20366         depth=depth+1;
20367         // we now consider each of the classes in partition depth and recurse upon each of them
20368         for (int i=0; i < K; i++){
20369 
20370                 if (*(argParts + Indices[depth*K+i] + 1) < 1) continue; // class is not active so move on
20371                 size_next = (*(dimClasses + depth*K+i ))-2;
20372                 if (size_next <= T) continue;
20373                 *(curbranch+depth) = i;
20374                 Util::explore2(argParts,Indices, dimClasses, nParts, K, T, curintx2, nintx, argParts + Indices[depth*K+i] + 2, size_next, depth,J, matchlist,
20375                         costlist, curbranch);
20376                 
20377         }
20378 
20379         delete[] curintx2;
20380 }

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

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 }

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

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

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

Definition at line 1682 of file util.h.

Referenced by EMAN::CtfAverager::add_image(), EMAN::CircularMaskProcessor::calc_locals(), EMAN::EMData::cut_slice(), EMAN::EMData::dot_rotate_translate(), EMAN::CtfAverager::finish(), EMAN::SymSearchProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), EMAN::TransformProcessor::transform(), and EMAN::EMData::unwrap().

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

Definition at line 2617 of file util_sparx.cpp.

References abs, bi, br, sgn(), 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, sgn(), 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(), 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, 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, 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 7709 of file util_sparx.cpp.

References ENTERFUNC, and EXITFUNC.

Referenced by voronoi().

07710 {
07711         ENTERFUNC;
07712         int i = k;
07713         while( i == k )  i = rand()%len;
07714         std::swap(key[i], key[k]);
07715         std::swap(x[i], x[k]);
07716         std::swap(y[i], y[k]);
07717         std::swap(z[i], z[k]);
07718         EXITFUNC;
07719 }

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, 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, and NullPointerException.

00218 {
00219         if (!data) {
00220                 throw NullPointerException("image data array");
00221         }
00222         Assert(nx > 0);
00223         Assert(ny > 0);
00224 
00225         float *buf = new float[nx];
00226         size_t row_size = nx * sizeof(float);
00227 
00228         for (size_t i = 0; i < ny / 2; i++) {
00229                 memcpy(buf, &data[i * nx], row_size);
00230                 memcpy(&data[i * nx], &data[(ny - 1 - i) * nx], row_size);
00231                 memcpy(&data[(ny - 1 - i) * nx], buf, row_size);
00232         }
00233 
00234         if( buf )
00235         {
00236                 delete[]buf;
00237                 buf = 0;
00238         }
00239 }

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

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

Definition at line 3091 of file util_sparx.cpp.

References circ, fftr_q(), EMAN::EMData::get_data(), log(), and numr.

Referenced by ali2d_ccf_list(), multiref_peaks_ali2d(), multiref_peaks_compress_ali2d(), multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), and multiref_polar_ali_helical().

03091                                                {
03092         int nring = numr.size()/3;
03093         float *circ = circp->get_data();
03094         int i, l;
03095         for (i=1; i<=nring;i++) {
03096 
03097 #ifdef _WIN32
03098                 l = (int)( log((float)numr(3,i))/log(2.0f) );
03099 #else
03100                 l=(int)(log2(numr(3,i)));
03101 #endif  //_WIN32
03102 
03103                 fftr_q(&circ(numr(2,i)),l);
03104         }
03105 }

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 }

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

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

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

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

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

19519 {
19520         int nx = mg->get_xsize();
19521         int ny = mg->get_ysize();
19522         int nz = mg->get_zsize();
19523 
19524         EMData* visited = new EMData();
19525         visited->set_size( nx, ny, nz );
19526         visited->to_zero();
19527         int grpid = 0;
19528         int maxgrp = 0;
19529         int maxsize = 0;
19530         for( int iz=0; iz < nz; ++iz ) {
19531                 for( int iy=0; iy < ny; ++iy ) {
19532                         for( int ix=0; ix < nx; ++ix ) {
19533                                 if( (*mg)(ix, iy, iz)==0.0 ) continue;
19534 
19535                                 if( (*visited)(ix, iy, iz) > 0.0 ) {
19536                                         // visited before, must be in other group.
19537                                         continue;
19538                                 }
19539 
19540                                 grpid++;
19541                                 int grpsize = find_group( ix, iy, iz, grpid, mg, visited );
19542                                 if( grpsize > maxsize ) {
19543                                         maxsize = grpsize;
19544                                         maxgrp = grpid;
19545                                 }
19546                         }
19547                 }
19548         }
19549 
19550         Assert( maxgrp > 0 );
19551 
19552         int npoint = 0;
19553         EMData* result = new EMData();
19554         result->set_size( nx, ny, nz );
19555         result->to_zero();
19556 
19557         for( int iz=0; iz < nz; ++iz ) {
19558                 for( int iy=0; iy < ny; ++iy ) {
19559                         for( int ix=0; ix < nx; ++ix ) {
19560                                 if( (*visited)(ix, iy, iz)==maxgrp ) {
19561                                         (*result)(ix,iy,iz) = 1.0;
19562                                         npoint++;
19563                                 }
19564                         }
19565                 }
19566         }
19567 
19568         Assert( npoint==maxsize );
19569         delete visited;
19570         return result;
19571 
19572 }

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(), EMAN::EMUtil::get_image_type(), and EMAN::EMUtil::is_valid_filename().

00493 {
00494     if (filename == "") {
00495         return "";
00496     }
00497 
00498         string result = "";
00499         const char *ext = strrchr(filename.c_str(), '.');
00500         if (ext) {
00501                 ext++;
00502                 result = string(ext);
00503         }
00504         return result;
00505 }

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

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

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(), and EMAN::Randnum::Instance().

00708 {
00709         Randnum* randnum = Randnum::Instance();
00710         return randnum->get_frand(lo, hi);
00711 }

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

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

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(), and EMAN::Randnum::Instance().

00702 {
00703         Randnum* randnum = Randnum::Instance();
00704         return randnum->get_frand(lo, hi);
00705 }

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

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

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(), move_points(), EMAN::KmeansSegmentProcessor::process(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), and EMAN::PointArray::set_from_density_map().

00697 {
00698         return get_frand((float)lo, (float)hi);
00699 }

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

Get a Gaussian random number.

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(), and EMAN::Randnum::Instance().

Referenced by EMAN::EmanOrientationGenerator::gen_orientations(), and EMAN::MaskNoiseProcessor::process_dist_pixel().

00809 {
00810         Randnum* randnum = Randnum::Instance();
00811         return randnum->get_gauss_rand(mean, sigma);
00812 }

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

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

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(), and EMAN::Randnum::Instance().

Referenced by EMAN::KMeansAnalyzer::analyze(), cluster_pairwise(), move_points(), and EMAN::KMeansAnalyzer::reseed().

00691 {
00692         Randnum* randnum = Randnum::Instance();
00693         return randnum->get_irand(lo, hi);
00694 }

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

Extract a single line from a multi-line string.

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

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 }

static 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 1827 of file util.h.

static 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 1809 of file util.h.

static 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 1798 of file util.h.

static 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 1778 of file util.h.

static 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 1759 of file util.h.

static 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 1748 of file util.h.

static 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 1732 of file util.h.

static 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 1721 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 EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), restrict1(), and round().

Referenced by Polar2Dmi(), EMAN::EMData::rot_scale_conv_new(), and EMAN::EMData::rot_scale_conv_new_3D().

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 EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), restrict1(), and round().

Referenced by EMAN::EMData::rot_scale_conv_new_background(), and EMAN::EMData::rot_scale_conv_new_background_3D().

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(), and EMAN::Randnum::Instance().

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

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, nx, ny, and EMAN::EMData::set_size().

20038                                                        {
20039 
20040         int nx = vol->get_xsize();
20041         int ny = vol->get_ysize();
20042         int nz = vol->get_zsize();
20043         float *vol_data = vol->get_data();
20044         int new_nx, new_ny;
20045 
20046         if (nz == 1)
20047                 throw ImageDimensionException("Error: Input must be a 3-D object");
20048         if ((dim < 1) || (dim > 3))
20049                 throw ImageDimensionException("Error: dim must be 1 (x-dimension), 2 (y-dimension) or 3 (z-dimension)");
20050         if (((dim == 1) && (index < 0 || index > nx-1)) ||
20051           ((dim == 1) && (index < 0 || index > nx-1)) ||
20052           ((dim == 1) && (index < 0 || index > nx-1)))
20053                 throw ImageDimensionException("Error: index exceeds the size of the 3-D object");
20054 
20055         if (dim == 1) {
20056                 new_nx = ny;
20057                 new_ny = nz;
20058         } else if (dim == 2) {
20059                 new_nx = nx;
20060                 new_ny = nz;
20061         } else {
20062                 new_nx = nx;
20063                 new_ny = ny;
20064         }
20065 
20066         EMData *slice = new EMData();
20067         slice->set_size(new_nx, new_ny, 1);
20068         float *slice_data = slice->get_data();
20069 
20070         if (dim == 1) {
20071                 for (int x=0; x<new_nx; x++)
20072                         for (int y=0; y<new_ny; y++)
20073                                 slice_data[y*new_nx+x] = vol_data[(y*ny+x)*nx+index];
20074         } else if (dim == 2) {
20075                 for (int x=0; x<new_nx; x++)
20076                         for (int y=0; y<new_ny; y++)
20077                                 slice_data[y*new_nx+x] = vol_data[(y*ny+index)*nx+x];
20078         } else {
20079                 for (int x=0; x<new_nx; x++)
20080                         for (int y=0; y<new_ny; y++)
20081                                 slice_data[y*new_nx+x] = vol_data[((size_t)index*ny+y)*nx+x];
20082         }
20083 
20084         return slice;
20085 }

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 EmptyContainerException, mean(), sqrt(), and square_sum().

00877 {
00878         // Note that this is a heavy STL approach using generic algorithms - some memory could be saved
00879         // using plain c style code, as in get_stats_cstyle below
00880 
00881         if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)");
00882 
00883         double sum = accumulate(data.begin(), data.end(), 0.0);
00884 
00885         double mean = sum / static_cast<double> (data.size());
00886 
00887         double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0;
00888 
00889         if (data.size() > 1)
00890         {
00891                 // read mm is "minus_mean"
00892                 vector<double> data_mm(data.size());
00893                 // read ts as "then squared"
00894                 vector<double> data_mm_sq(data.size());
00895 
00896                 // Subtract the mean from the data and store it in data_mm
00897                 transform(data.begin(), data.end(), data_mm.begin(), std::bind2nd(std::minus<double>(), mean));
00898 
00899                 // Get the square of the data minus the mean and store it in data_mm_sq
00900                 transform(data_mm.begin(), data_mm.end(), data_mm.begin(), data_mm_sq.begin(), std::multiplies<double>());
00901 
00902                 // Get the sum of the squares for the calculation of the standard deviation
00903                 double square_sum = accumulate(data_mm_sq.begin(), data_mm_sq.end(), 0.0);
00904 
00905                 //Calculate teh standard deviation
00906                 std_dev = sqrt(square_sum / static_cast<double>(data.size()-1));
00907                 double std_dev_sq = std_dev * std_dev;
00908 
00909                 // The numerator for the skewness fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00910                 double cubic_sum = inner_product(data_mm.begin(), data_mm.end(),data_mm_sq.begin(), 0.0);
00911 
00912                 // The numerator for the kurtosis fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00913                 double quartic_sum = inner_product(data_mm_sq.begin(), data_mm_sq.end(),data_mm_sq.begin(), 0.0);
00914 
00915                 // Finalize the calculation of the skewness and kurtosis, as defined in
00916                 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00917                 skewness = cubic_sum / ((data.size()-1) * std_dev_sq * std_dev );
00918                 kurtosis = quartic_sum / ((data.size()-1) * std_dev_sq * std_dev_sq );
00919 
00920         }
00921 
00922         Dict parms;
00923         parms["mean"] = mean;
00924         parms["std_dev"] = std_dev;
00925         parms["skewness"] = skewness;
00926         parms["kurtosis"] = kurtosis;
00927 
00928         return parms;
00929 }

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

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

Definition at line 932 of file util.cpp.

References EmptyContainerException, mean(), sqrt(), square(), and square_sum().

00933 {
00934         if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)");
00935 
00936         double square_sum = 0.0, sum = 0.0, cube_sum = 0.0, quart_sum = 0.0;
00937         for( vector<float>::const_iterator it = data.begin(); it != data.end(); ++it )
00938         {
00939                 double val = *it;
00940                 double square = val*val;
00941                 quart_sum += square*square;
00942                 cube_sum += square*val;
00943                 square_sum += square;
00944                 sum += val;
00945         }
00946 
00947         double mean = sum/(double)data.size();
00948 
00949         double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0;
00950 
00951         if (data.size() > 1)
00952         {
00953                 // The standard deviation is calculated here
00954                 std_dev = sqrt( (square_sum - mean*sum)/(double)(data.size()-1));
00955 
00956                 double square_mean = mean*mean;
00957                 double cube_mean = mean*square_mean;
00958 
00959                 double square_std_dev = std_dev*std_dev;
00960 
00961                 // This is the numerator of the skewness fraction, if you expand the brackets, as defined in
00962                 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00963                 double cubic_sum = cube_sum - 3*square_sum*mean + 3*sum*square_mean - cube_mean*data.size();
00964                 // Complete the skewness fraction
00965                 skewness = cubic_sum/((data.size()-1)*square_std_dev*std_dev);
00966 
00967                 // This is the numerator of the kurtosis fraction, if you expand the brackets, as defined in
00968                 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00969                 double quartic_sum = quart_sum - 4*cube_sum*mean + 6*square_sum*square_mean - 4*sum*cube_mean  + square_mean*square_mean*data.size();
00970                 // Complete the kurtosis fraction
00971                 kurtosis = quartic_sum /( (data.size()-1)*square_std_dev*square_std_dev);
00972         }
00973 
00974         Dict parms;
00975         parms["mean"] = mean;
00976         parms["std_dev"] = std_dev;
00977         parms["skewness"] = skewness;
00978         parms["kurtosis"] = kurtosis;
00979 
00980         return parms;
00981 }

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

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

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

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.

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.

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 }

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

Definition at line 1911 of file util.h.

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

Check whether a number is a good float.

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

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 1894 of file util.h.

Referenced by EMAN::FRCCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::EMObject::EMObject(), EMAN::ByteOrder::is_float_big_endian(), EMAN::NormalizeProcessor::process_inplace(), and EMAN::FiniteProcessor::process_pixel().

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

Definition at line 5570 of file util_sparx.cpp.

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

05571 {
05572         float *img_ptr = img->get_data();
05573         float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data();
05574 
05575         int *img_freq_bin = new int[3*hist_len];
05576         for(int i = 0;i < (3*hist_len);i++) img_freq_bin[i] = 0;
05577         for(size_t i = 0;i < size_img;++i) {
05578                 if(mask_ptr[i] > 0.5f) {
05579                         float img_xn = img_ptr[i]*PA + PB;
05580                         int L = static_cast<int>(((img_xn - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1);
05581                         if(L >= 0 && L < (3*hist_len)) img_freq_bin[L]++;
05582                 }
05583         }
05584         int freq_hist = 0;
05585 
05586         for(int i = 0;i < (3*hist_len);i++) freq_hist += (int)pow((float)((int)ref_freq_hist[i] - (int)img_freq_bin[i]),2.f);
05587         freq_hist = (-freq_hist);
05588         return static_cast<float>(freq_hist);
05589 }

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

Definition at line 5478 of file util_sparx.cpp.

References B, data, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, infomask(), EMAN::EMData::is_complex(), and min.

05479 {
05480         /* Exception Handle */
05481         if (img->is_complex() || ref->is_complex())
05482                 throw ImageFormatException("Cannot do Histogram on Fourier Image");
05483 
05484         if(mask != NULL){
05485                 if(img->get_xsize() != mask->get_xsize() || img->get_ysize() != mask->get_ysize() || img->get_zsize() != mask->get_zsize())
05486                         throw ImageDimensionException("The size of mask image should be of same size as the input image"); }
05487         /* ===================================================== */
05488 
05489         /* Image size calculation */
05490         size_t size_ref = ((size_t)(ref->get_xsize())*(ref->get_ysize())*(ref->get_zsize()));
05491         size_t size_img = ((size_t)(img->get_xsize())*(img->get_ysize())*(img->get_zsize()));
05492         /* ===================================================== */
05493 
05494         /* The reference image attributes */
05495         float *ref_ptr = ref->get_data();
05496         float ref_h_min = ref->get_attr("minimum");
05497         float ref_h_max = ref->get_attr("maximum");
05498         float ref_h_avg = ref->get_attr("mean");
05499         float ref_h_sig = ref->get_attr("sigma");
05500         /* ===================================================== */
05501 
05502         /* Input image under mask attributes */
05503         float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data();
05504 
05505         vector<float> img_data = Util::infomask(img, mask);
05506         float img_avg = img_data[0];
05507         float img_sig = img_data[1];
05508 
05509         /* The image under mask -- size calculation */
05510         int cnt=0;
05511         for(size_t i=0;i<size_img;++i)
05512                 if (mask_ptr[i]>0.5f)
05513                                 cnt++;
05514         /* ===================================================== */
05515 
05516         /* Histogram of reference image calculation */
05517         float ref_h_diff = ref_h_max - ref_h_min;
05518 
05519         #ifdef _WIN32
05520                 int hist_len = _cpp_min((unsigned long)size_ref/16,_cpp_min((unsigned long)size_img/16,256lu));
05521         #else
05522                 int hist_len = std::min((unsigned long)size_ref/16,std::min((unsigned long)size_img/16,256lu));
05523         #endif  //_WIN32
05524 
05525         float *ref_freq_bin = new float[3*hist_len];
05526 
05527         //initialize value in each bin to zero
05528         for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] = 0.f;
05529 
05530         for (size_t i = 0;i < size_ref;++i) {
05531                 int L = static_cast<int>(((ref_ptr[i] - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1);
05532                 ref_freq_bin[L]++;
05533         }
05534         for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] *= static_cast<float>(cnt)/static_cast<float>(size_ref);
05535 
05536         //Parameters Calculation (i.e) 'A' x + 'B'
05537         float A = ref_h_sig/img_sig;
05538         float B = ref_h_avg - (A*img_avg);
05539 
05540         vector<float> args;
05541         args.push_back(A);
05542         args.push_back(B);
05543 
05544         vector<float> scale;
05545         scale.push_back(1.e-7f*A);
05546         scale.push_back(-1.e-7f*B);
05547 
05548         vector<float> ref_freq_hist;
05549         for(int i = 0;i < (3*hist_len);i++) ref_freq_hist.push_back((int)ref_freq_bin[i]);
05550 
05551         vector<float> data;
05552         data.push_back(ref_h_diff);
05553         data.push_back(ref_h_min);
05554 
05555         Dict parameter;
05556 
05557         /* Parameters displaying the arguments A & B, and the scaling function and the data's */
05558         parameter["args"] = args;
05559         parameter["scale"]= scale;
05560         parameter["data"] = data;
05561         parameter["ref_freq_bin"] = ref_freq_hist;
05562         parameter["size_img"]=(double)size_img;
05563         parameter["hist_len"]=hist_len;
05564         /* ===================================================== */
05565 
05566         return parameter;
05567 }

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

Definition at line 5420 of file util_sparx.cpp.

References EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, EMAN::EMData::is_complex(), nx, and ny.

05421 {
05422         if (image->is_complex())
05423                 throw ImageFormatException("Cannot do histogram on Fourier image");
05424         //float hmax, hmin;
05425         float *imageptr=0, *maskptr=0;
05426         int nx=image->get_xsize();
05427         int ny=image->get_ysize();
05428         int nz=image->get_zsize();
05429 
05430         if(mask != NULL){
05431                 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize())
05432                         throw ImageDimensionException("The size of mask image should be of same size as the input image");
05433                 maskptr =mask->get_data();
05434         }
05435         if( nbins == 0) nbins = nx;
05436         vector <float> freq(2*nbins, 0.0);
05437 
05438         imageptr=image->get_data();
05439         if( hmin == hmax ) {
05440                 if(mask == NULL) {
05441                         hmax = image->get_attr("maximum");
05442                         hmin = image->get_attr("minimum");
05443                 } else {
05444                         bool  First = true;
05445                         for (size_t i = 0;i < (size_t)nx*ny*nz; i++) {
05446                         if (maskptr[i]>=0.5f) {
05447                                         if(First) {
05448                                                 hmax = imageptr[i];
05449                                                 hmin = imageptr[i];
05450                                                 First = false;
05451                                         } else {
05452                                                 hmax = (hmax < imageptr[i])?imageptr[i]:hmax;
05453                                                 hmin = (hmin > imageptr[i])?imageptr[i]:hmin;
05454                                         }
05455                                 }
05456                         }
05457                 }
05458         }
05459         float hdiff = hmax - hmin;
05460         float ff = (nbins-1)/hdiff;
05461         for (int i = 0; i < nbins; i++) freq[nbins+i] = hmin + (float(i)+0.5f)/ff;
05462         if(mask == NULL) {
05463                 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) {
05464                         int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5);
05465                         if(jbin >= 1 && jbin <= nbins)  freq[jbin-1] += 1.0;
05466                 }
05467         } else {
05468                 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) {
05469                         if(maskptr[i] >= 0.5) {
05470                                 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5);
05471                                 if(jbin >= 1 && jbin <= nbins)  freq[jbin-1] += 1.0;
05472                         }
05473                 }
05474         }
05475         return freq;
05476 }

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

Definition at line 7130 of file util_sparx.cpp.

References cmp1(), cmp2(), ENTERFUNC, EXITFUNC, key, phi, and theta.

07131 {
07132         ENTERFUNC;
07133         vector<tmpstruct> tmp(len);
07134         int i;
07135         for(i = 1;i<=len;i++)
07136         {
07137                 tmp[i-1].theta1 = theta(i);
07138                 tmp[i-1].phi1 = phi(i);
07139                 tmp[i-1].key1 = key(i);
07140         }
07141 
07142         if (option == 1) sort(tmp.begin(),tmp.end(),Util::cmp1);
07143         if (option == 2) sort(tmp.begin(),tmp.end(),Util::cmp2);
07144 
07145         for(i = 1;i<=len;i++)
07146         {
07147                 theta(i) = tmp[i-1].theta1;
07148                 phi(i)   = tmp[i-1].phi1;
07149                 key(i)   = tmp[i-1].key1;
07150         }
07151         EXITFUNC;
07152 }

static 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 1602 of file util.h.

static 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 1657 of file util.h.

static 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 1646 of file util.h.

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

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

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 1635 of file util.h.

Referenced by EMAN::EMData::calc_radial_dist(), EMAN::PhaseCmp::cmp(), EMAN::Interp::init_gimx(), EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::KmeansSegmentProcessor::process(), EMAN::DistanceSegmentProcessor::process(), EMAN::TestImageSphericalWave::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), and EMAN::RotationalAverageProcessor::process_inplace().

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

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 1624 of file util.h.

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

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

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 1613 of file util.h.

Referenced by EMAN::FourierInserter3DMode7::insert_pixel(), EMAN::FourierInserter3DMode6::insert_pixel(), EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::FourierInserter3DMode2::insert_pixel(), EMAN::GaussFFTProjector::interp_ft_3d(), EMAN::WienerFourierReconstructor::pixel_at(), and EMAN::FourierReconstructor::pixel_at().

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

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

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.

Referenced by EMAN::EMData::calc_az_dist(), EMAN::EMData::calc_radial_dist(), and EMAN::EMAN2Ctf::compute_2d_complex().

00714 {
00715 static float *mem = (float *)malloc(4*128*128);
00716 static int dim = 0;
00717 x=abs(x);
00718 y=abs(y);
00719 
00720 if (x>=dim || y>=dim) {
00721         if (x>2048 || y>2048) return (float)hypot((float)x,(float)y);           // We won't cache anything bigger than 4096^2
00722         dim=x>=dim?x+1:dim;
00723         dim=y>=dim?y+1:dim;
00724         mem=(float*)realloc(mem,4*dim*dim);
00725         for (int y=0; y<dim; y++) {
00726                 for (int x=0; x<dim; x++) {
00727 #ifdef  _WIN32
00728                         mem[x+y*dim]=(float)_hypot((float)x,(float)y);
00729 #else
00730                         mem[x+y*dim]=hypot((float)x,(float)y);
00731 #endif
00732                 }
00733         }
00734 }
00735 
00736 return mem[x+y*dim];
00737 }

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

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

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

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, ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), ImageFormatException, EMAN::EMUtil::is_same_size(), LOGERR, nx, ny, EMAN::EMData::set_size(), EMAN::EMData::to_one(), and EMAN::EMData::update().

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

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

20087                                                           {
20088         int nx = img->get_xsize();
20089         float min = img->get_attr("minimum");
20090         float max = img->get_attr("maximum");
20091         float* img_data = img->get_data();
20092         array_mutation(img_data, nx*nx, mutation_rate, min, max, 8, 0);
20093         return;
20094 }

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

Definition at line 62 of file util_sparx.cpp.

References ENTERFUNC, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, LOGERR, nx, ny, and sqrt().

00063              :  find statistics under the mask (mask >0.5)
00064 //  flip false: find statistics ourside the mask (mask <0.5)
00065 {
00066         ENTERFUNC;
00067         vector<float> stats;
00068         float *Volptr, *maskptr,MAX,MIN;
00069         long double Sum1,Sum2;
00070         long count;
00071 
00072         MAX = -FLT_MAX;
00073         MIN =  FLT_MAX;
00074         count = 0L;
00075         Sum1  = 0.0L;
00076         Sum2  = 0.0L;
00077 
00078         if (mask == NULL) {
00079                 //Vol->update_stat();
00080                 stats.push_back(Vol->get_attr("mean"));
00081                 stats.push_back(Vol->get_attr("sigma"));
00082                 stats.push_back(Vol->get_attr("minimum"));
00083                 stats.push_back(Vol->get_attr("maximum"));
00084                 return stats;
00085         }
00086 
00087         /* Check if the sizes of the mask and image are same */
00088 
00089         size_t nx = Vol->get_xsize();
00090         size_t ny = Vol->get_ysize();
00091         size_t nz = Vol->get_zsize();
00092 
00093         size_t mask_nx = mask->get_xsize();
00094         size_t mask_ny = mask->get_ysize();
00095         size_t mask_nz = mask->get_zsize();
00096 
00097         if  (nx != mask_nx || ny != mask_ny || nz != mask_nz )
00098                 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!");
00099 
00100  /*       if (nx != mask_nx ||
00101             ny != mask_ny ||
00102             nz != mask_nz  ) {
00103            // should throw an exception here!!! (will clean it up later CY)
00104            fprintf(stderr, "The dimension of the image does not match the dimension of the mask!\n");
00105            fprintf(stderr, " nx = %d, mask_nx = %d\n", nx, mask_nx);
00106            fprintf(stderr, " ny = %d, mask_ny = %d\n", ny, mask_ny);
00107            fprintf(stderr, " nz = %d, mask_nz = %d\n", nz, mask_nz);
00108            exit(1);
00109         }
00110  */
00111         Volptr = Vol->get_data();
00112         maskptr = mask->get_data();
00113 
00114         for (size_t i = 0; i < (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 20382 of file util_sparx.cpp.

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

20382                                                                                                    {
20383         //cout<<"initial_prune\n";
20384         // simple initial pruning. For class indClass of partition indPart:
20385         // 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
20386         // If for some partition (not equal to indPart) for which there is no such class, then return 0 immediately.
20387 
20388         // 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
20389 
20390         // remember when calling k_means_cont_table, the first element of each class is an index, and actual number of elements in the class
20391         // (as stored in dimClasses) should be decremented by 1 accordingly, and second is dummy variable
20392 
20393         int* dummy(0);
20394         int* cref;
20395         int cref_size;
20396         int* ccomp;
20397         int ccomp_size;
20398         int nintx;
20399         for (int i=0; i < nParts; i++){
20400                 for (int j =0; j < K; j++){
20401 
20402                         // consider class Parts[i][j]
20403                         cref = Parts[i][j];//incr by 1 since first element is index and second is dummy
20404                         cref_size = (*(dimClasses+i*K+(*cref)))-2;
20405 
20406 
20407                         if (cref_size <= T){
20408 
20409                                 *cref = -1;
20410                                 continue;
20411                         }
20412                         bool done = 0;
20413                         for (int a = 0; a < nParts; a++){
20414                                 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
20415                                 bool hasActive=0;
20416                                 for (unsigned int b=0; b < Parts[a].size(); b++){
20417                                         // get the card of the intx between Parts[i][j] and Parts[a][b] using k_means_cont_table
20418                                         // remember first element of each class is the index of the class
20419                                         ccomp = Parts[a][b];
20420                                         ccomp_size= (*(dimClasses+a*K+(*ccomp)))-2;
20421                                         nintx = Util::k_means_cont_table_(cref+2,ccomp+2, dummy, cref_size, ccomp_size,0);
20422 
20423 
20424                                         if (nintx <= T)
20425                                                 *(ccomp+1) = 0; // class Parts[a][b] is 'inactive' for cref
20426                                         else{
20427                                                 *(ccomp+1)=1; // class Parts[a][b] is 'active' for cref
20428                                                 hasActive=1;
20429                                         }
20430                                 }
20431                                 // see if partition a has at least one active class.if not then we're done with cref
20432                                 if (hasActive < 1){
20433                                    done=1;
20434                                    break;
20435                                 }
20436 
20437                         }
20438 
20439                         if (done > 0){
20440                                 // remove class j from partition i
20441 
20442                                 *cref = -1; // mark for deletion later
20443                                 continue; // move on to class Parts[i][j+1]
20444                         }
20445 
20446                         // now we adopt more aggressive measures. we find the match with the largest weight which has class Parts[i][j] for partition i.
20447                         // 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.
20448 
20449                         // (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.
20450                         // Note that if there are ALOT of partitions, then sorting the partititions may actually take longer than the time saved by ordering hte
20451                         // partitions. However, we do not have a lot of partitions, (usually around 10), so sorting time will be trivial compared to exploring time.
20452 
20453                         // explore returns one if there is a feasible matching containing class cref which has weight gt T, and otherwise returns 0
20454                         //bool found = 1;
20455                         bool found = explore(Parts, dimClasses, nParts, K, T, i, cref+2, cref_size, cref, cref_size,0);
20456 
20457                         if (found<1){ // There is NO feasible matching with class j (cref)  with weight greater than T, so delete this class from Parts
20458                                 // Parts[i].erase(Parts[i].begin()+j);
20459                                 *cref = -1;
20460                         }
20461                 }
20462 
20463                 // Erase from Parts[i] all the classes that's being designated for erasure
20464 
20465                 for (int d = K-1; d > -1; d--){
20466                         if (*(Parts[i][d]) < 0) Parts[i].erase(Parts[i].begin()+d);
20467                 }
20468 
20469         }
20470         //cout <<"number of classes left in each partition after initial prune\n";      
20471         // Print out how many classes are left in each partition
20472         //for (int i =0; i < nParts; i++)
20473         //      cout << Parts[i].size()<<", ";
20474         //cout << "\n";
20475 }

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(), EMAN::SpiderIO::SpiderIO(), and EMAN::EMData::write_image().

00209 {
00210         if (access(filename.c_str(), F_OK) == 0) {
00211                 return true;
00212         }
00213         return false;
00214 }

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

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

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

Definition at line 2099 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 5107 of file util_sparx.cpp.

References max.

05107                                                                                                     {
05108     long int d2 = group2[s2 - 1] - group2[0];
05109     long int p2 = 0;
05110     long int i1 = 0;
05111     long int i2 = 0;
05112     long int max = 0;
05113     long int cont = 0;
05114     long int i = 0;
05115     int stop1 = 0;
05116     int stop2 = 0;
05117 
05118     for (i=0; i<s1; i++) {
05119         p2 = (long int)(s2 * (double)group1[i] / (double)d2);
05120         if (p2 >= s2) {p2 = s2 - 1;}
05121         i1 = p2;
05122         i2 = p2;
05123         max = s2;
05124         if (group1[i] < group2[0] || group1[i] > group2[s2 - 1]) {continue;}
05125 
05126         stop1 = 0;
05127         stop2 = 0;
05128         while (max--) {
05129             if (group1[i] == group2[i1]) {
05130                 if (flag) {stb[cont] = group1[i];}
05131                 cont++;
05132                 break;
05133             }
05134             if (group2[i1] < group1[i]) {stop1=1;}
05135             if (group1[i] == group2[i2]) {
05136                 if (flag) {stb[cont] = group1[i];}
05137                 cont++;
05138                 break;
05139             }
05140             if (group2[i2] > group1[i]) {stop2=1;}
05141             //printf("i1 %li i2 %li    v2 %i v2 %i   stop1 %i stop2 %i\n", i1, i2, group2[i1], group2[i2], stop1, stop2);
05142 
05143             if (stop1 & stop2) {break;}
05144             i1--;
05145             i2++;
05146             if (i1 < 0) {i1 = 0;}
05147             if (i2 >= s2) {i2 = s2 - 1;}
05148         }
05149         //printf("v1: %i    ite: %li   cont: %li\n", group1[i], s2-max, cont);
05150     }
05151 
05152     return cont;
05153 }

static 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 1468 of file util.h.

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

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

Definition at line 20150 of file util_sparx.cpp.

References q, and t.

20150                                                                                                                              {
20151 
20152         if (is_mirror != 0) {
20153                 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) {
20154                         int r = rand()%10000;
20155                         float f = r/10000.0f;
20156                         if (f < mutation_rate) *q = 1-*q;
20157                 }
20158         } else {
20159                 map<int, vector<int> >  graycode;
20160                 map<vector<int>, int> rev_graycode;
20161                 vector <int> gray;
20162 
20163                 int K=1;
20164                 for (int i=0; i<L; i++) K*=2;
20165 
20166                 for (int k=0; k<K; k++) {
20167                         int shift = 0;
20168                         vector <int> gray;
20169                         for (int i=L-1; i>-1; i--) {
20170                                 int t = ((k>>i)%2-shift)%2;
20171                                 gray.push_back(t);
20172                                 shift += t-2;
20173                         }
20174                         graycode[k] = gray;
20175                         rev_graycode[gray] = k;
20176                 }
20177 
20178                 float gap = (K-1)/(max_val-min_val);
20179                 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) {
20180                         float val = *q;
20181                         if (val < min_val) { val = min_val; }
20182                         else if  (val > max_val) { val = max_val; }
20183                         int k = int((val-min_val)*gap+0.5);
20184                         vector<int> gray = graycode[k];
20185                         bool changed = false;
20186                         for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) {
20187                                 int r = rand()%10000;
20188                                 float f = r/10000.0f;
20189                                 if (f < mutation_rate) {
20190                                         *p = 1-*p;
20191                                         changed = true;
20192                                 }
20193                         }
20194                         if (changed) {
20195                                 k = rev_graycode[gray];
20196                                 *q = k/gap+min_val;
20197                         }
20198                 }
20199         }
20200         return list;
20201 }

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

References cl1().

06338 {
06339     /* System generated locals */
06340     long int q_dim1, q_offset, q1_dim1, q1_offset, i__1, i__2;
06341 
06342     /* Local variables */
06343     long int i__, j, m, n1, ii, jj;
06344     double tmp;
06345     vector<float> p;
06346     --x;
06347     q_dim1 = *klm2d;
06348     q_offset = 1 + q_dim1;
06349     q -= q_offset;
06350     q1_dim1 = *klm2d;
06351     q1_offset = 1 + q1_dim1;
06352     q1 -= q1_offset;
06353     --s;
06354     --res;
06355     iu -= 3;
06356     cu -= 3;
06357 
06358     /* Function Body */
06359     long int l = 0;
06360 
06361 /* C==ZHONG HUANG,JULY,12,02;L=0,1,2,3,4,5,6 correspond to different equality constraints */
06362     m = *ks;
06363     n1 = *n + 1;
06364     if (*iswi == 1) {
06365         i__1 = n1;
06366         for (jj = 1; jj <= i__1; ++jj) {
06367             i__2 = *ks;
06368             for (ii = 1; ii <= i__2; ++ii) {
06369         /*      q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];*/
06370 
06371                 q[*ks + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]
06372                         ;
06373             }
06374         }
06375     } else if (*iswi == 2) {
06376         i__1 = *ks;
06377         for (ii = 1; ii <= i__1; ++ii) {
06378             i__2 = n1;
06379             for (jj = 1; jj <= i__2; ++jj) {
06380                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06381                 q[*ks + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06382             }
06383         }
06384     } else if (*iswi == 3) {
06385         l = 2;
06386         i__1 = n1;
06387         for (jj = 1; jj <= i__1; ++jj) {
06388             i__2 = *ks + 2;
06389             for (ii = 1; ii <= i__2; ++ii) {
06390                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06391             }
06392             i__2 = *ks;
06393             for (ii = 1; ii <= i__2; ++ii) {
06394                 q[*ks + 2 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06395             }
06396         }
06397     } else if (*iswi == 4) {
06398         l = 2;
06399         i__1 = n1;
06400         for (jj = 1; jj <= i__1; ++jj) {
06401             i__2 = *ks + 2;
06402             for (ii = 1; ii <= i__2; ++ii) {
06403                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06404             }
06405             i__2 = *ks;
06406             for (ii = 1; ii <= i__2; ++ii) {
06407                 q[*ks + 2 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06408             }
06409         }
06410     } else if (*iswi == 5) {
06411         l = 1;
06412         i__1 = n1;
06413         for (jj = 1; jj <= i__1; ++jj) {
06414             i__2 = *ks + 1;
06415             for (ii = 1; ii <= i__2; ++ii) {
06416                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06417             }
06418             i__2 = *ks;
06419             for (ii = 1; ii <= i__2; ++ii) {
06420                 q[*ks + 1 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06421             }
06422         }
06423     } else if (*iswi == 6) {
06424         l = 1;
06425         i__1 = n1;
06426         for (jj = 1; jj <= i__1; ++jj) {
06427             i__2 = *ks + 1;
06428             for (ii = 1; ii <= i__2; ++ii) {
06429                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06430             }
06431             i__2 = *ks;
06432             for (ii = 1; ii <= i__2; ++ii) {
06433                 q[*ks + 1 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06434             }
06435         }
06436     } else if (*iswi == 7) {
06437         l = 3;
06438         i__1 = n1;
06439         for (jj = 1; jj <= i__1; ++jj) {
06440             i__2 = *ks + 3;
06441             for (ii = 1; ii <= i__2; ++ii) {
06442                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06443             }
06444             i__2 = *ks;
06445             for (ii = 1; ii <= i__2; ++ii) {
06446                 q[*ks + 3 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06447             }
06448         }
06449     } else if (*iswi == 8) {
06450         l = 4;
06451         i__1 = n1;
06452         for (jj = 1; jj <= i__1; ++jj) {
06453             i__2 = *ks + 4;
06454             for (ii = 1; ii <= i__2; ++ii) {
06455                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06456             }
06457             i__2 = *ks;
06458             for (ii = 1; ii <= i__2; ++ii) {
06459                 q[*ks + 4 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06460             }
06461         }
06462     }
06463 
06464     Util::cl1(ks, &l, &m, n, klm2d, &q[q_offset], &x[1], &res[1], &cu[3], &iu[3], &s[1]);
06465     i__1 = *ks;
06466     int tmp__j=0;
06467     for (i__ = 1; i__ <= i__1; ++i__) {
06468         tmp = 0.f;
06469         i__2 = *n - 1;
06470         for (j = 1; j <= i__2; ++j) {
06471         tmp__j=j;
06472             tmp += pow(q1[i__ + q1_dim1], tmp__j) * x[j];
06473         }
06474         tmp += x[*n];
06475         p.push_back(static_cast<float>(exp(tmp)));
06476         p.push_back(q1[i__ + q1_dim1]);
06477     }
06478     i__2=*n;
06479     for (i__=1;i__<=i__2;++i__)
06480         { p.push_back(static_cast<float>(x[i__]));}
06481     return p;
06482 }

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

Definition at line 17473 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update().

17474 {
17475         ENTERFUNC;
17476         /* Exception Handle */
17477         if (!img) {
17478                 throw NullPointerException("NULL input image");
17479         }
17480         /* ==============   img += scalar*img1   ================ */
17481 
17482         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17483         size_t size = (size_t)nx*ny*nz;
17484         float *img_ptr  =img->get_data();
17485         float *img1_ptr = img1->get_data();
17486         for (size_t i=0;i<size;++i)img_ptr[i] += img1_ptr[i]*scalar;
17487         img1->update();
17488 
17489         EXITFUNC;
17490 }

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

Definition at line 17283 of file util_sparx.cpp.

References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update().

17284 {
17285         ENTERFUNC;
17286         /* Exception Handle */
17287         if (!img) {
17288                 throw NullPointerException("NULL input image");
17289         }
17290         /* ==============   output = img + scalar*img1   ================ */
17291 
17292         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17293         size_t size = (size_t)nx*ny*nz;
17294         EMData * img2 = img->copy_head();
17295         float *img_ptr  =img->get_data();
17296         float *img2_ptr = img2->get_data();
17297         float *img1_ptr = img1->get_data();
17298         for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i]*scalar;
17299         img2->update();
17300         if(img->is_complex()) {
17301                 img2->set_complex(true);
17302                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17303         }
17304 
17305         EXITFUNC;
17306         return img2;
17307 }

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

Definition at line 1037 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 6119 of file util_sparx.cpp.

06120 {
06121         vector<float>new_peak;
06122         int n1=peak1.size()/3;
06123         float p_size2=p_size*p_size;
06124         for (int i=0;i<n1;++i) {
06125                 vector<float>::iterator it2= peak1.begin()+3*i;
06126                 bool push_back1=true;
06127                 int n2=peak2.size()/3;
06128                 /*cout<<"peak2 size==="<<n2<<"i====="<<i<<endl;
06129                        cout<<"new peak size==="<<new_peak.size()/3<<endl;*/
06130                 if(n2 ==0) {
06131                         new_peak.push_back(*it2);
06132                         new_peak.push_back(*(it2+1));
06133                         new_peak.push_back(*(it2+2));
06134                 } else  {
06135                         int j=0;
06136                         while (j< n2-1 ) {
06137                                 vector<float>::iterator it3= peak2.begin()+3*j;
06138                                 float d2=((*(it2+1))-(*(it3+1)))*((*(it2+1))-(*(it3+1)))+((*(it2+2))-(*(it3+2)))*((*(it2+2))-(*(it3+2)));
06139                                 if(d2< p_size2 ) {
06140                                         if( (*it2)<(*it3) ) {
06141                                                 new_peak.push_back(*it3);
06142                                                 new_peak.push_back(*(it3+1));
06143                                                 new_peak.push_back(*(it3+2));
06144                                                 peak2.erase(it3);
06145                                                 peak2.erase(it3);
06146                                                 peak2.erase(it3);
06147                                                 push_back1=false;
06148                                         } else {
06149                                                 peak2.erase(it3);
06150                                                 peak2.erase(it3);
06151                                                 peak2.erase(it3);
06152                                         }
06153                                 } else  j=j+1;
06154                                 n2=peak2.size()/3;
06155                         }
06156                         if(push_back1) {
06157                                 new_peak.push_back(*it2);
06158                                 new_peak.push_back(*(it2+1));
06159                                 new_peak.push_back(*(it2+2));
06160                         }
06161                 }
06162         }
06163         return new_peak;
06164 }

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

helper function for k-means

Definition at line 5032 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), nx, and ny.

05032                                                                    {
05033         ENTERFUNC;
05034 
05035         int nima = data.size();
05036         vector<float> res(nima);
05037         double result = 0.;
05038         double valmin = 1.0e20;
05039         int valpos = -1;
05040 
05041         for (int kk=0; kk<nima; kk++){
05042         result = 0;
05043         //validate_input_args(image, data[kk]);
05044 
05045         float *y_data = data[kk]->get_data();
05046         float *x_data = image->get_data();
05047 
05048         // Implemented by PAP  01/09/06 - please do not change.  If in doubts, write/call me.
05049         int nx  = data[kk]->get_xsize();
05050         int ny  = data[kk]->get_ysize();
05051         nx = (nx - 2 + data[kk]->is_fftodd()); // nx is the real-space size of the input image
05052         int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image
05053 
05054         int ixb = 2*((nx+1)%2);
05055         int iyb = ny%2;
05056         int iz = 0;
05057 
05058         for ( int iy = 0; iy <= ny-1; iy++) {
05059             for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) {
05060                 int ii = ix + (iy  + iz * ny)* lsd2;
05061                 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05062             }
05063         }
05064         for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
05065             int ii = (iy  + iz * ny)* lsd2;
05066             result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05067             result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
05068         }
05069         if(nx%2 == 0) {
05070             for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
05071                 int ii = lsd2 - 2 + (iy  + iz * ny)* lsd2;
05072                 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05073                 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
05074             }
05075 
05076         }
05077         result *= 2;
05078         result += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]);
05079         if(ny%2 == 0) {
05080             int ii = (ny/2  + iz * ny)* lsd2;
05081             result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05082         }
05083         if(nx%2 == 0) {
05084             int ii = lsd2 - 2 + (0  + iz * ny)* lsd2;
05085             result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05086             if(ny%2 == 0) {
05087                 int ii = lsd2 - 2 +(ny/2  + iz * ny)* lsd2;
05088                 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05089             }
05090         }
05091 
05092         result /= (long int)nx*(long int)ny*(long int)nx*(long int)ny;
05093         res[kk] = (float)result;
05094 
05095         if(result<valmin) {valmin = result; valpos = kk;}
05096 
05097         }
05098 
05099         Dict retvals;
05100         retvals["dist"] = res;
05101         retvals["pos"]  = valpos;
05102 
05103         EXITFUNC;
05104         return retvals;
05105 }

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

k-means helper

Definition at line 4997 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), and EMAN::EMData::get_ysize().

04997                                                                    {
04998         ENTERFUNC;
04999 
05000         int nima = data.size();
05001         vector<float> res(nima);
05002         double result = 0.;
05003         double valmin = 1.0e20;
05004         int valpos = -1;
05005 
05006         for (int kk=0; kk<nima; kk++){
05007         result = 0;
05008 
05009         float *y_data = data[kk]->get_data();
05010         float *x_data = image->get_data();
05011         long totsize = image->get_xsize()*image->get_ysize();
05012         for (long i = 0; i < totsize; i++) {
05013             double temp = x_data[i]- y_data[i];
05014             result += temp*temp;
05015         }
05016         result /= totsize;
05017         res[kk] = (float)result;
05018 
05019         if(result<valmin) {valmin = result; valpos = kk;}
05020 
05021         }
05022 
05023         Dict retvals;
05024         retvals["dist"] = res;
05025         retvals["pos"]  = valpos;
05026 
05027         EXITFUNC;
05028         return retvals;
05029 
05030 }

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

Definition at line 1022 of file util.h.

Referenced by cluster_pairwise().

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

Definition at line 19326 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), get_frand(), get_irand(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, NullPointerException, nx, ny, EMAN::EMData::set_size(), EMAN::EMData::to_zero(), and EMAN::EMData::update().

19327 {
19328         ENTERFUNC;
19329         /* Exception Handle */
19330         if (!img) {
19331                 throw NullPointerException("NULL input image");
19332         }
19333 
19334         int newx, newy, newz;
19335         bool  keep_going;
19336         cout << " entered   " <<endl;
19337         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
19338         //int size = nx*ny*nz;
19339         EMData * img2 = new EMData();
19340         img2->set_size(nx,ny,nz);
19341         img2->to_zero();
19342         float *img_ptr  =img->get_data();
19343         float *img2_ptr = img2->get_data();
19344         int r2 = ro*ro;
19345         int r3 = r2*ro;
19346         int ri2 = ri*ri;
19347         int ri3 = ri2*ri;
19348 
19349         int n2 = nx/2;
19350 
19351         for (int k=-n2; k<=n2; k++) {           //cout << " k   "<<k <<endl;
19352                 float z2 = static_cast<float>(k*k);
19353                 for (int j=-n2; j<=n2; j++) {
19354                         float y2 = z2 + j*j;
19355                         if(y2 <= r2) {
19356                                                                                         //cout << "  j  "<<j <<endl;
19357 
19358                                 for (int i=-n2; i<=n2; i++) {
19359                                         float x2 = y2 + i*i;
19360                                         if(x2 <= r3) {
19361                                                                                         //cout << "  i  "<<i <<endl;
19362                                                 int ib = i+n2; int jb = j+n2; int kb = k+n2;
19363                                                 if(x2 >= ri3) {
19364                                                         //  this is the outer shell, here points can only vanish
19365                                                         if(img_ptr(ib,jb,kb) == 1.0f) {
19366                                                                 //cout << "  1  "<<ib <<endl;
19367                                                                 if(Util::get_frand(0.0f, 1.0f) > qprob){
19368                                                                         img2_ptr(ib,jb,kb) = 0.0f;
19369                                                                         keep_going = true;
19370                                                                 //cout << "  try  "<<ib <<endl;
19371                                                                         while(keep_going) {
19372                                                                                 newx = Util::get_irand(-ro,ro);
19373                                                                                 newy = Util::get_irand(-ro,ro);
19374                                                                                 newz = Util::get_irand(-ro,ro);
19375                                                                                 if(newx*newx+newy*newy+newz*newz <= r3) {
19376                                                                                         newx += n2; newy += n2; newz += n2;
19377                                                                                         if( img_ptr(newx,newy,newz) == 0.0f) {
19378                                                                                                 img2_ptr(newx,newy,newz) = 1.0f;
19379                                                                                                 keep_going = false; }
19380                                                                                 }
19381                                                                         }
19382                                                                 }   else  img2_ptr(ib,jb,kb) = 1.0f;
19383                                                         }
19384                                                 }  else  {
19385                                                         // this is inner shell, the point can only move (or vanish, if all neighbors exist)
19386                                                         if(img_ptr(ib,jb,kb) == 1.0) {
19387                                                                 if(Util::get_frand(0.0f,1.0f) > qprob) {
19388                                                                         //  find out the number of neighbors
19389                                                                         float  numn = -1.0f;  // we already know the central one is 1
19390                                                                         for (newz = -1; newz <= 1; newz++)
19391                                                                                 for (newy = -1; newy <= 1; newy++)
19392                                                                                         for (newx = -1; newx <= 1; newx++)
19393                                                                                                 numn += img_ptr(ib+newx,jb+newy,kb+newz);
19394                                                                         img2_ptr(ib,jb,kb) = 0.0;
19395                                                                         if(numn == 26.0f) {
19396                                                                                 //  all neighbors exist, it has to vanish
19397                                                                                 keep_going = true;
19398                                                                                 while(keep_going) {
19399                                                                                         newx = Util::get_irand(-ro,ro);
19400                                                                                         newy = Util::get_irand(-ro,ro);
19401                                                                                         newz = Util::get_irand(-ro,ro);
19402                                                                                         if(newx*newx+newy*newy+newz*newz < r3) {
19403                                                                                                 newx += n2; newy += n2; newz += n2;
19404                                                                                                 if( img_ptr(newx,newy,newz) == 0.0f) {
19405                                                                                                         if(newx*newx+newy*newy+newz*newz < r3) {
19406                                                                                                                 if(newx*newx+newy*newy+newz*newz < r3) {
19407                                                                                                                         newx += n2; newy += n2; newz += n2;
19408                                                                                                                         if( img_ptr(newx,newy,newz) == 0.0f) {
19409                                                                                                                                 img2_ptr(newx,newy,newz) = 1.0f;
19410                                                                                                                                 keep_going = false; }
19411                                                                                                                 }
19412                                                                                                         }
19413                                                                                                 }
19414                                                                                         }
19415                                                                                 }
19416                                                                         }  else if(numn == 25.0f) {
19417                                                                                 // there is only one empty neighbor, move there
19418                                                                                 for (newz = -1; newz <= 1; newz++) {
19419                                                                                         for (newy = -1; newy <= 1; newy++) {
19420                                                                                                 for (newx = -1; newx <= 1; newx++) {
19421                                                                                                         if( newx != 0 && newy != 0 && newz != 0) {
19422                                                                                                                 if(img_ptr(newx+ib,newy+jb,newz+kb) == 0.0f) {
19423                                                                                                                         img2_ptr(newx+ib,newy+jb,newz+kb) = 1.0f;
19424                                                                                                                         }
19425                                                                                                         }
19426                                                                                                 }
19427                                                                                         }
19428                                                                                 }
19429                                                                         }  else {
19430                                                                                 //  more than one neighbor is zero, select randomly one and move there
19431                                                                                 keep_going = true;
19432                                                                                 while(keep_going) {
19433                                                                                         newx = Util::get_irand(-1,1);
19434                                                                                         newy = Util::get_irand(-1,1);
19435                                                                                         newz = Util::get_irand(-1,1);
19436                                                                                         if(newx != 0 && newy != 0 && newz != 0)  {
19437                                                                                                 if(img_ptr(ib+newx,jb+newy,kb+newz) == 0.0f) {
19438                                                                                                         img2_ptr(ib+newx,jb+newy,kb+newz) = 1.0f;//?????
19439                                                                                                         keep_going = false;
19440                                                                                                 }
19441                                                                                         }
19442                                                                                 }
19443                                                                         }
19444                                                                 }  else img2_ptr(ib,jb,kb) = 1.0f;
19445                                                         }
19446                                                 }
19447                                         }
19448                                 }
19449                         }
19450                 }
19451         }
19452         //for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + Util::get_irand(1,7);
19453         img2->update();
19454 
19455         EXITFUNC;
19456         return img2;
19457 }

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

Definition at line 17572 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update().

17573 {
17574         ENTERFUNC;
17575         /* Exception Handle */
17576         if (!img) {
17577                 throw NullPointerException("NULL input image");
17578         }
17579         /* ========= img *= img1 ===================== */
17580 
17581         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17582         size_t size = (size_t)nx*ny*nz;
17583         float *img_ptr  = img->get_data();
17584         float *img1_ptr = img1->get_data();
17585         if(img->is_complex()) {
17586                 for (size_t i=0; i<size; i+=2) {
17587                         float tmp     = img_ptr[i] * img1_ptr[i]   - img_ptr[i+1] * img1_ptr[i+1] ;
17588                         img_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ;
17589                         img_ptr[i]   = tmp;
17590 
17591                 }
17592         } else {
17593                 for (size_t i=0;i<size;++i) img_ptr[i] *= img1_ptr[i];
17594         }
17595         img->update();
17596 
17597         EXITFUNC;
17598 }

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

Definition at line 17455 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update().

17456 {
17457         ENTERFUNC;
17458         /* Exception Handle */
17459         if (!img) {
17460                 throw NullPointerException("NULL input image");
17461         }
17462         /* ============  output = scalar*input  ================== */
17463 
17464         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17465         size_t size = (size_t)nx*ny*nz;
17466         float *img_ptr  =img->get_data();
17467         for (size_t i=0;i<size;++i) img_ptr[i] *= scalar;
17468         img->update();
17469 
17470         EXITFUNC;
17471 }

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

Definition at line 17361 of file util_sparx.cpp.

References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update().

17362 {
17363         ENTERFUNC;
17364         /* Exception Handle */
17365         if (!img) {
17366                 throw NullPointerException("NULL input image");
17367         }
17368         /* ==============   output = img * img1   ================ */
17369 
17370         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17371         size_t size = (size_t)nx*ny*nz;
17372         EMData * img2 = img->copy_head();
17373         float *img_ptr  =img->get_data();
17374         float *img2_ptr = img2->get_data();
17375         float *img1_ptr = img1->get_data();
17376         if(img->is_complex()) {
17377                 for (size_t i=0; i<size; i+=2) {
17378                         img2_ptr[i]   = img_ptr[i] * img1_ptr[i]   - img_ptr[i+1] * img1_ptr[i+1] ;
17379                         img2_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ;
17380                 }
17381                 img2->set_complex(true);
17382                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17383         } else {
17384                 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] * img1_ptr[i];
17385                 img2->update();
17386         }
17387 
17388         EXITFUNC;
17389         return img2;
17390 }

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

Definition at line 17258 of file util_sparx.cpp.

References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update().

17259 {
17260         ENTERFUNC;
17261         /* Exception Handle */
17262         if (!img) {
17263                 throw NullPointerException("NULL input image");
17264         }
17265         /* ============  output = scalar*input  ================== */
17266 
17267         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17268         size_t size = (size_t)nx*ny*nz;
17269         EMData * img2 = img->copy_head();
17270         float *img_ptr  =img->get_data();
17271         float *img2_ptr = img2->get_data();
17272         for (size_t i=0;i<size;++i)img2_ptr[i] = img_ptr[i]*scalar;
17273         img2->update();
17274 
17275         if(img->is_complex()) {
17276                 img2->set_complex(true);
17277                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17278         }
17279         EXITFUNC;
17280         return img2;
17281 }

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

Definition at line 19029 of file util_sparx.cpp.

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

19029                                                                                       {
19030         
19031         const int nmax=args.size(), mmax=nmax;
19032         char task[60], csave[60];
19033         long int lsave[4];
19034         long int n, m, iprint, isave[44];
19035         long int* nbd = new long int[nmax];
19036         long int* iwa = new long int[3*nmax];
19037         double f, factr, pgtol;
19038         double* x = new double[nmax];
19039         double* l = new double[nmax];
19040         double* u = new double[nmax];
19041         double* g = new double[nmax];
19042         double dsave[29];
19043         double* wa = new double[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax];
19044         long int SIXTY=60;
19045 
19046         int num_ali = nmax/3+1;
19047         int nima = all_ali_params.size()/(num_ali*4);
19048         
19049         //     We wish to have no output.
19050         iprint = -1;
19051 
19052         //c     We specify the tolerances in the stopping criteria.
19053         factr=1.0e1;
19054         pgtol=1.0e-9;
19055 
19056         //     We specify the dimension n of the sample problem and the number
19057         //        m of limited memory corrections stored.  (n and m should not
19058         //        exceed the limits nmax and mmax respectively.)
19059         n=nmax;
19060         m=mmax;
19061 
19062         //     We now provide nbd which defines the bounds on the variables:
19063         //                    l   specifies the lower bounds,
19064         //                    u   specifies the upper bounds.
19065         //                    x   specifies the initial guess
19066         for (int i=0; i<nmax; i++) {
19067                 x[i] = args[i]; 
19068                 nbd[i] = 0;
19069         }
19070         
19071         //     We start the iteration by initializing task.
19072         // (**MUST clear remaining chars in task with spaces (else crash)!**)
19073         strcpy(task,"START");
19074         for (int i=5;i<60;i++)  task[i]=' ';
19075 
19076         //     This is the call to the L-BFGS-B code.
19077         // (* call the L-BFGS-B routine with task='START' once before loop *)
19078         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19079         int step = 1;
19080 
19081         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
19082         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
19083 
19084                 if (strncmp(task,"FG",2)==0) {
19085                 //   the minimization routine has returned to request the
19086                 //   function f and gradient g values at the current x
19087 
19088                 //        Compute function value f for the sample problem.
19089                 f = multi_align_error_func(x, all_ali_params, nima, num_ali);
19090 
19091                 //        Compute gradient g for the sample problem.
19092                 multi_align_error_dfunc(x, all_ali_params, nima, num_ali, g);
19093                 }
19094 
19095                 //c          go back to the minimization routine.
19096                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19097                 step++;
19098         }
19099 
19100         //printf("Total step is %d\n", step);
19101         vector<float> res;
19102         for (int i=0; i<nmax; i++) res.push_back(static_cast<float>(x[i]));
19103         res.push_back(f);
19104         
19105         delete[] nbd;
19106         delete[] iwa;
19107         delete[] x;
19108         delete[] l;
19109         delete[] u;
19110         delete[] g;
19111         delete[] wa;
19112         
19113         return res;
19114 
19115 }

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

Definition at line 19173 of file util_sparx.cpp.

References mean(), and rot_shift().

Referenced by multi_align_error().

19173                                                                                                             {
19174 
19175         
19176         for (int i=0; i<num_ali*3-3; i++) g[i] = 0.0;
19177         
19178         float x1 = 1.0;
19179         float y1 = 0.0;
19180         float x2 = 0.0;
19181         float y2 = 1.0;
19182 
19183         float* x1_new = new float[num_ali];
19184         float* y1_new = new float[num_ali];
19185         float* x2_new = new float[num_ali];
19186         float* y2_new = new float[num_ali];
19187 
19188         float* alpha12_0 = new float[num_ali-1];
19189         float* dalpha12 = new float[num_ali-1];
19190         float* dsx12 = new float[num_ali-1];
19191         float* dsy12 = new float[num_ali-1];
19192         float* mirror1_0 = new float[num_ali-1];
19193 
19194         for (int i=0; i<nima; i++) {
19195                 
19196                 float alpha2 = all_ali_params[(num_ali-1)*(nima*4)+i*4];
19197                 float sx2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+1];
19198                 float sy2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+2];
19199                 
19200                 rot_shift(x1, y1, alpha2, sx2, sy2, x1_new+num_ali-1, y1_new+num_ali-1);
19201                 rot_shift(x2, y2, alpha2, sx2, sy2, x2_new+num_ali-1, y2_new+num_ali-1);
19202                 
19203                 for (int j=0; j<num_ali-1; j++) {
19204                         float alpha1 = all_ali_params[j*(nima*4)+i*4];
19205                         float sx1 = all_ali_params[j*(nima*4)+i*4+1];
19206                         float sy1 = all_ali_params[j*(nima*4)+i*4+2];
19207                         int mirror1 = static_cast<int>(all_ali_params[j*(nima*4)+i*4+3]);
19208 
19209                         float alphai = x[j*3];
19210                         float sxi = x[j*3+1];
19211                         float syi = x[j*3+2];
19212 
19213                         float cosi = cos(alphai/180.0f*M_PI);
19214                         float sini = sin(alphai/180.0f*M_PI);
19215                         
19216                         float alpha12, sx12, sy12;
19217                         int mirror12;
19218                         if (mirror1 == 0) {
19219                                 alpha12 = fmod(alpha1+alphai, 360.0f);
19220                                 rot_shift(sx1, sy1, alphai, sxi, syi, &sx12, &sy12);
19221                                 mirror12 = 0;
19222                         } else {
19223                                 alpha12 = fmod(alpha1-alphai, 360.0f);
19224                                 rot_shift(sx1, sy1, -alphai, -sxi, syi, &sx12, &sy12);
19225                                 mirror12 = 1;
19226                         }
19227 
19228                         rot_shift(x1, y1, alpha12, sx12, sy12, x1_new+j, y1_new+j);
19229                         rot_shift(x2, y2, alpha12, sx12, sy12, x2_new+j, y2_new+j);
19230                 
19231                         alpha12_0[j] = alpha12;
19232                         mirror1_0[j] = mirror1;
19233                         if (mirror1 == 0) {
19234                                 dalpha12[j] = M_PI/180.0f;
19235                                 dsx12[j] = (-sini*sx1+cosi*sy1)/180.0f*M_PI;
19236                                 dsy12[j] = (-cosi*sx1-sini*sy1)/180.0f*M_PI;
19237                         } else {
19238                                 dalpha12[j] = -M_PI/180.0f;
19239                                 dsx12[j] = (sini*(-sx1)-cosi*sy1)/180.0f*M_PI;
19240                                 dsy12[j] = (-cosi*(-sx1)-sini*sy1)/180.0f*M_PI;
19241                         }
19242                 }
19243 
19244                 for (int j=0; j<num_ali-1; j++) {
19245                         float cosa = cos(alpha12_0[j]/180.0f*M_PI);
19246                         float sina = sin(alpha12_0[j]/180.0f*M_PI);
19247                         float diffx1 = x1_new[j]-mean(x1_new, num_ali);
19248                         float diffx2 = x2_new[j]-mean(x2_new, num_ali);
19249                         float diffy1 = y1_new[j]-mean(y1_new, num_ali);
19250                         float diffy2 = y2_new[j]-mean(y2_new, num_ali);
19251 
19252                         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]);
19253                         g[j*3] += p;
19254                 
19255                         p = diffx1+diffx2;
19256                         if (mirror1_0[j] == 0) g[j*3+1] += p;
19257                         else g[j*3+1] -= p;
19258 
19259                         p = diffy1+diffy2;
19260                         g[j*3+2] += p;
19261                 }
19262         }
19263 
19264         delete[] x1_new;
19265         delete[] y1_new;
19266         delete[] x2_new;
19267         delete[] y2_new;
19268         delete[] alpha12_0;
19269         delete[] dalpha12;
19270         delete[] dsx12;
19271         delete[] dsy12;
19272         delete[] mirror1_0;
19273         
19274 }

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

Definition at line 19117 of file util_sparx.cpp.

References rot_shift(), and var().

Referenced by multi_align_error().

19117                                                                                                  {
19118 
19119         float x1 = 1.0;
19120         float y1 = 0.0;
19121         float x2 = 0.0;
19122         float y2 = 1.0;
19123 
19124         float all_var = 0;
19125         float* x1_new = new float[num_ali];
19126         float* y1_new = new float[num_ali];
19127         float* x2_new = new float[num_ali];
19128         float* y2_new = new float[num_ali];
19129 
19130         for (int i=0; i<nima; i++) {
19131                 float alpha2 = all_ali_params[(num_ali-1)*(nima*4)+i*4];
19132                 float sx2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+1];
19133                 float sy2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+2];
19134                 
19135                 rot_shift(x1, y1, alpha2, sx2, sy2, x1_new+num_ali-1, y1_new+num_ali-1);
19136                 rot_shift(x2, y2, alpha2, sx2, sy2, x2_new+num_ali-1, y2_new+num_ali-1);
19137                 for (int j=0; j<num_ali-1; j++) {
19138                         float alpha1 = all_ali_params[j*(nima*4)+i*4];
19139                         float sx1 = all_ali_params[j*(nima*4)+i*4+1];
19140                         float sy1 = all_ali_params[j*(nima*4)+i*4+2];
19141                         int mirror1 = static_cast<int>(all_ali_params[j*(nima*4)+i*4+3]);
19142 
19143                         float alphai = x[j*3];
19144                         float sxi = x[j*3+1];
19145                         float syi = x[j*3+2];
19146 
19147                         float alpha12, sx12, sy12;
19148                         int mirror12;
19149                         if (mirror1 == 0) {
19150                                 alpha12 = fmod(alpha1+alphai, 360.0f);
19151                                 rot_shift(sx1, sy1, alphai, sxi, syi, &sx12, &sy12);
19152                                 mirror12 = 0;
19153                         } else {
19154                                 alpha12 = fmod(alpha1-alphai, 360.0f);
19155                                 rot_shift(sx1, sy1, -alphai, -sxi, syi, &sx12, &sy12);
19156                                 mirror12 = 1;
19157                         }
19158 
19159                         rot_shift(x1, y1, alpha12, sx12, sy12, x1_new+j, y1_new+j);
19160                         rot_shift(x2, y2, alpha12, sx12, sy12, x2_new+j, y2_new+j);
19161                 }
19162                 
19163                 float p = var(x1_new, num_ali)+var(y1_new, num_ali)+var(x2_new, num_ali)+var(y2_new, num_ali);
19164                 all_var += p;
19165         }
19166         delete[] x1_new;
19167         delete[] y1_new;
19168         delete[] x2_new;
19169         delete[] y2_new;
19170         return all_var/static_cast<float>(nima);
19171 }

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

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

18410                                                       {
18411 
18412         int   maxrin = numr[numr.size()-1];
18413 
18414         int   ky = int(2*yrng/step+0.5)/2;
18415         int   kx = int(2*xrng/step+0.5)/2;
18416 
18417         peaks->set_size(maxrin, 2*kx+3, 2*ky+3);
18418         float *p_ccf1ds = peaks->get_data();
18419 
18420         peakm->set_size(maxrin, 2*kx+3, 2*ky+3);
18421         float *p_ccf1dm = peakm->get_data();
18422 
18423         for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) {
18424                 p_ccf1ds[i] = -1.e20f;
18425                 p_ccf1dm[i] = -1.e20f;
18426         }
18427 
18428         for (int i = -ky; i <= ky; i++) {
18429                 float iy = i * step;
18430                 for (int j = -kx; j <= kx; j++) {
18431                         float ix = j*step;
18432                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18433                         Frngs(cimage, numr);
18434                         Crosrng_msg_vec(crefim, cimage, numr,
18435                           p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin,
18436                           p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin);
18437                         delete cimage; cimage = 0;
18438                 }
18439         }
18440         return;
18441 }

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

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

18445                                                      {
18446 
18447         int   maxrin = numr[numr.size()-1];
18448 
18449         int   ky = int(2*yrng/step+0.5)/2;
18450         int   kx = int(2*xrng/step+0.5)/2;
18451 
18452         peaks->set_size(maxrin, 2*kx+3, 2*ky+3);
18453         float *p_ccf1ds = peaks->get_data();
18454 
18455         peakm->set_size(maxrin, 2*kx+3, 2*ky+3);
18456         float *p_ccf1dm = peakm->get_data();
18457 
18458         peaks_compress->set_size(maxrin, 1, 1);
18459         float *p_ccf1ds_compress = peaks_compress->get_data();
18460 
18461         peakm_compress->set_size(maxrin, 1, 1);
18462         float *p_ccf1dm_compress = peakm_compress->get_data();
18463 
18464         for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) {
18465                 p_ccf1ds[i] = -1.e20f;
18466                 p_ccf1dm[i] = -1.e20f;
18467         }
18468 
18469         for (int i = -ky; i <= ky; i++) {
18470                 float iy = i * step;
18471                 for (int j = -kx; j <= kx; j++) {
18472                         float ix = j*step;
18473                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18474                         Frngs(cimage, numr);
18475                         Crosrng_msg_vec(crefim, cimage, numr,
18476                           p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin,
18477                           p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin);
18478                         delete cimage; cimage = 0;
18479                 }
18480         }
18481         for (int x=0; x<maxrin; x++) {
18482                 float maxs = -1.0e22f;
18483                 float maxm = -1.0e22f;
18484                 for (int i=1; i<=2*ky+1; i++) {
18485                         for (int j=1; j<=2*kx+1; j++) {
18486                                 if (p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x] > maxs) maxs = p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x];
18487                                 if (p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x] > maxm) maxm = p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x];
18488                         }
18489                 }
18490                 p_ccf1ds_compress[x] = maxs;
18491                 p_ccf1dm_compress[x] = maxm;
18492         }
18493         return;
18494 }

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

References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), pi, and Polar2Dm().

17783                                                        {
17784 
17785     // Manually extract.
17786 /*    vector< EMAN::EMData* > crefim;
17787     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
17788     crefim.reserve(crefim_len);
17789 
17790     for(std::size_t i=0;i<crefim_len;i++) {
17791         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
17792         crefim.push_back(proxy());
17793     }
17794 */
17795 
17796         size_t crefim_len = crefim.size();
17797 
17798         int   ky = int(2*yrng/step+0.5)/2;
17799         int   kx = int(2*xrng/step+0.5)/2;
17800         int   iref, nref=0, mirror=0;
17801         float iy, ix, sx=0, sy=0;
17802         float peak = -1.0E23f;
17803         float ang=0.0f;
17804         for (int i = -ky; i <= ky; i++) {
17805                 iy = i * step ;
17806                 for (int j = -kx; j <= kx; j++) {
17807                         ix = j*step ;
17808                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
17809 
17810                         Normalize_ring( cimage, numr );
17811 
17812                         Frngs(cimage, numr);
17813                         //  compare with all reference images
17814                         // for iref in xrange(len(crefim)):
17815                         for ( iref = 0; iref < (int)crefim_len; iref++) {
17816                                 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
17817                                 double qn = retvals["qn"];
17818                                 double qm = retvals["qm"];
17819                                 if(qn >= peak || qm >= peak) {
17820                                         sx = -ix;
17821                                         sy = -iy;
17822                                         nref = iref;
17823                                         if (qn >= qm) {
17824                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
17825                                                 peak = static_cast<float>(qn);
17826                                                 mirror = 0;
17827                                         } else {
17828                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
17829                                                 peak = static_cast<float>(qm);
17830                                                 mirror = 1;
17831                                         }
17832                                 }
17833                         }  delete cimage; cimage = 0;
17834                 }
17835         }
17836         float co, so, sxs, sys;
17837         co = static_cast<float>( cos(ang*pi/180.0) );
17838         so = static_cast<float>( -sin(ang*pi/180.0) );
17839         sxs = sx*co - sy*so;
17840         sys = sx*so + sy*co;
17841         vector<float> res;
17842         res.push_back(ang);
17843         res.push_back(sxs);
17844         res.push_back(sys);
17845         res.push_back(static_cast<float>(mirror));
17846         res.push_back(static_cast<float>(nref));
17847         res.push_back(peak);
17848         return res;
17849 }

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

References ang_n(), Crosrng_ms_delta(), Frngs(), Normalize_ring(), pi, and Polar2Dm().

17949                                                                                        {
17950 
17951     // Manually extract.
17952 /*    vector< EMAN::EMData* > crefim;
17953     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
17954     crefim.reserve(crefim_len);
17955 
17956     for(std::size_t i=0;i<crefim_len;i++) {
17957         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
17958         crefim.push_back(proxy());
17959     }
17960 */
17961 
17962         size_t crefim_len = crefim.size();
17963 
17964         int   ky = int(2*yrng/step+0.5)/2;
17965         int   kx = int(2*xrng/step+0.5)/2;
17966         int   iref, nref=0, mirror=0;
17967         float iy, ix, sx=0, sy=0;
17968         float peak = -1.0E23f;
17969         float ang=0.0f;
17970         for (int i = -ky; i <= ky; i++) {
17971                 iy = i * step ;
17972                 for (int j = -kx; j <= kx; j++) {
17973                         ix = j*step ;
17974                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
17975 
17976                         Normalize_ring( cimage, numr );
17977 
17978                         Frngs(cimage, numr);
17979                         //  compare with all reference images
17980                         // for iref in xrange(len(crefim)):
17981                         for ( iref = 0; iref < (int)crefim_len; iref++) {
17982                                 Dict retvals = Crosrng_ms_delta(crefim[iref], cimage, numr, delta_start, delta);
17983                                 double qn = retvals["qn"];
17984                                 double qm = retvals["qm"];
17985                                 if(qn >= peak || qm >= peak) {
17986                                         sx = -ix;
17987                                         sy = -iy;
17988                                         nref = iref;
17989                                         if (qn >= qm) {
17990                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
17991                                                 peak = static_cast<float>(qn);
17992                                                 mirror = 0;
17993                                         } else {
17994                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
17995                                                 peak = static_cast<float>(qm);
17996                                                 mirror = 1;
17997                                         }
17998                                 }
17999                         }  delete cimage; cimage = 0;
18000                 }
18001         }
18002         float co, so, sxs, sys;
18003         co = static_cast<float>( cos(ang*pi/180.0) );
18004         so = static_cast<float>( -sin(ang*pi/180.0) );
18005         sxs = sx*co - sy*so;
18006         sys = sx*so + sy*co;
18007         vector<float> res;
18008         res.push_back(ang);
18009         res.push_back(sxs);
18010         res.push_back(sys);
18011         res.push_back(static_cast<float>(mirror));
18012         res.push_back(static_cast<float>(nref));
18013         res.push_back(peak);
18014         return res;
18015 }

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

References abs, ang_n(), Crosrng_ms(), Frngs(), get_attr(), EMAN::EMData::get_attr(), Normalize_ring(), phi, pi, Polar2Dm(), t, and theta.

18076                                                        {
18077 
18078     // Manually extract.
18079 /*    vector< EMAN::EMData* > crefim;
18080     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18081     crefim.reserve(crefim_len);
18082 
18083     for(std::size_t i=0;i<crefim_len;i++) {
18084         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18085         crefim.push_back(proxy());
18086     }
18087 */
18088         size_t crefim_len = crefim.size();
18089         const float qv = static_cast<float>( pi/180.0 );
18090 
18091         Transform * t = image->get_attr("xform.projection");
18092         Dict d = t->get_params("spider");
18093         if(t) {delete t; t=0;}
18094         float phi = d["phi"];
18095         float theta = d["theta"];
18096         int   ky = int(2*yrng/step+0.5)/2;
18097         int   kx = int(2*xrng/step+0.5)/2;
18098         int   iref, nref=0, mirror=0;
18099         float iy, ix, sx=0, sy=0;
18100         float peak = -1.0E23f;
18101         float ang=0.0f;
18102         float imn1 = sin(theta*qv)*cos(phi*qv);
18103         float imn2 = sin(theta*qv)*sin(phi*qv);
18104         float imn3 = cos(theta*qv);
18105         vector<float> n1(crefim_len);
18106         vector<float> n2(crefim_len);
18107         vector<float> n3(crefim_len);
18108         for ( iref = 0; iref < (int)crefim_len; iref++) {
18109                         n1[iref] = crefim[iref]->get_attr("n1");
18110                         n2[iref] = crefim[iref]->get_attr("n2");
18111                         n3[iref] = crefim[iref]->get_attr("n3");
18112         }
18113         for (int i = -ky; i <= ky; i++) {
18114             iy = i * step ;
18115             for (int j = -kx; j <= kx; j++) {
18116                 ix = j*step;
18117                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18118 
18119                 Normalize_ring( cimage, numr );
18120 
18121                 Frngs(cimage, numr);
18122                 //  compare with all reference images
18123                 // for iref in xrange(len(crefim)):
18124                 for ( iref = 0; iref < (int)crefim_len; iref++) {
18125                         if(abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18126                                 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
18127                                 double qn = retvals["qn"];
18128                                 double qm = retvals["qm"];
18129                                 if(qn >= peak || qm >= peak) {
18130                                         sx = -ix;
18131                                         sy = -iy;
18132                                         nref = iref;
18133                                         if (qn >= qm) {
18134                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18135                                                 peak = static_cast<float>( qn );
18136                                                 mirror = 0;
18137                                         } else {
18138                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18139                                                 peak = static_cast<float>( qm );
18140                                                 mirror = 1;
18141                                         }
18142                                 }
18143                         }
18144                 }  delete cimage; cimage = 0;
18145             }
18146         }
18147         float co, so, sxs, sys;
18148         if(peak == -1.0E23) {
18149                 ang=0.0; sxs=0.0; sys=0.0; mirror=0;
18150                 nref = -1;
18151         } else {
18152                 co =  cos(ang*qv);
18153                 so = -sin(ang*qv);
18154                 sxs = sx*co - sy*so;
18155                 sys = sx*so + sy*co;
18156         }
18157         vector<float> res;
18158         res.push_back(ang);
18159         res.push_back(sxs);
18160         res.push_back(sys);
18161         res.push_back(static_cast<float>(mirror));
18162         res.push_back(static_cast<float>(nref));
18163         res.push_back(peak);
18164         return res;
18165 }

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

References abs, ang_n(), Crosrng_sm_psi(), Frngs(), get_attr(), EMAN::EMData::get_attr(), Normalize_ring(), phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta.

18169                                                        {
18170 
18171     // Manually extract.
18172 /*    vector< EMAN::EMData* > crefim;
18173     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18174     crefim.reserve(crefim_len);
18175 
18176     for(std::size_t i=0;i<crefim_len;i++) {
18177         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18178         crefim.push_back(proxy());
18179     }
18180 */
18181         size_t crefim_len = crefim.size();
18182         const float qv = static_cast<float>(pi/180.0);
18183 
18184         Transform* t = image->get_attr("xform.projection");
18185         Dict d = t->get_params("spider");
18186         if(t) {delete t; t=0;}
18187         float phi = d["phi"];
18188         float theta = d["theta"];
18189         float psi = d["psi"];
18190         int ky = int(2*yrng/step+0.5)/2;
18191         int kx = int(2*xrng/step+0.5)/2;
18192         int iref, nref = 0, mirror = 0;
18193         float iy, ix, sx = 0, sy = 0;
18194         float peak = -1.0E23f;
18195         float ang = 0.0f;
18196         float imn1 = sin(theta*qv)*cos(phi*qv);
18197         float imn2 = sin(theta*qv)*sin(phi*qv);
18198         float imn3 = cos(theta*qv);
18199         vector<float> n1(crefim_len);
18200         vector<float> n2(crefim_len);
18201         vector<float> n3(crefim_len);
18202         for (iref = 0; iref < (int)crefim_len; iref++) {
18203                         n1[iref] = crefim[iref]->get_attr("n1");
18204                         n2[iref] = crefim[iref]->get_attr("n2");
18205                         n3[iref] = crefim[iref]->get_attr("n3");
18206         }
18207         bool nomirror = (theta<90.0) || ((theta==90.0) && (psi<psi_max));
18208         if (!nomirror) {
18209                 phi = fmod(phi+540.0f, 360.0f);
18210                 theta = 180-theta;
18211                 psi = fmod(540.0f-psi, 360.0f);
18212         }
18213         for (int i = -ky; i <= ky; i++) {
18214             iy = i * step ;
18215             for (int j = -kx; j <= kx; j++) {
18216                 ix = j*step;
18217                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18218 
18219                 Normalize_ring(cimage, numr);
18220 
18221                 Frngs(cimage, numr);
18222                 //  compare with all reference images
18223                 // for iref in xrange(len(crefim)):
18224                 for (iref = 0; iref < (int)crefim_len; iref++) {
18225                         if (abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18226                                 if (nomirror) {
18227                                         Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 0);
18228                                         double qn = retvals["qn"];
18229                                         if (qn >= peak) {
18230                                                 sx = -ix;
18231                                                 sy = -iy;
18232                                                 nref = iref;
18233                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18234                                                 peak = static_cast<float>(qn);
18235                                                 mirror = 0;
18236                                         }
18237                                 } else {
18238                                         Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 1);
18239                                         double qn = retvals["qn"];
18240                                         if (qn >= peak) {
18241                                                 sx = -ix;
18242                                                 sy = -iy;
18243                                                 nref = iref;
18244                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18245                                                 peak = static_cast<float>(qn);
18246                                                 mirror = 1;
18247                                         }
18248                                 }
18249                         }
18250                 }  delete cimage; cimage = 0;
18251             }
18252         }
18253         float co, so, sxs, sys;
18254         if(peak == -1.0E23) {
18255                 ang=0.0; sxs=0.0; sys=0.0; mirror=0;
18256                 nref = -1;
18257         } else {
18258                 co =  cos(ang*qv);
18259                 so = -sin(ang*qv);
18260                 sxs = sx*co - sy*so;
18261                 sys = sx*so + sy*co;
18262         }
18263         vector<float> res;
18264         res.push_back(ang);
18265         res.push_back(sxs);
18266         res.push_back(sys);
18267         res.push_back(static_cast<float>(mirror));
18268         res.push_back(static_cast<float>(nref));
18269         res.push_back(peak);
18270         return res;
18271 }

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

References ang_n(), Crosrng_ns(), Frngs(), pi, and Polar2Dm().

18019                                                          {
18020 
18021     // Manually extract.
18022 /*    vector< EMAN::EMData* > crefim;
18023     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18024     crefim.reserve(crefim_len);
18025 
18026     for(std::size_t i=0;i<crefim_len;i++) {
18027         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18028         crefim.push_back(proxy());
18029     }
18030 */
18031         size_t crefim_len = crefim.size();
18032 
18033         int   ky = int(2*yrng/step+0.5)/2;
18034         int   kx = int(2*xrng/step+0.5)/2;
18035         int   iref, nref=0;
18036         float iy, ix, sx=0, sy=0;
18037         float peak = -1.0E23f;
18038         float ang=0.0f;
18039         for (int i = -ky; i <= ky; i++) {
18040                 iy = i * step ;
18041                 for (int j = -kx; j <= kx; j++) {
18042                         ix = j*step ;
18043                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18044                         Frngs(cimage, numr);
18045                         //  compare with all reference images
18046                         // for iref in xrange(len(crefim)):
18047                         for ( iref = 0; iref < (int)crefim_len; iref++) {
18048                                 Dict retvals = Crosrng_ns(crefim[iref], cimage, numr);
18049                                 double qn = retvals["qn"];
18050                                 if(qn >= peak) {
18051                                         sx = -ix;
18052                                         sy = -iy;
18053                                         nref = iref;
18054                                         ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18055                                         peak = static_cast<float>(qn);
18056                                 }
18057                         }  delete cimage; cimage = 0;
18058                 }
18059         }
18060         float co, so, sxs, sys;
18061         co = static_cast<float>( cos(ang*pi/180.0) );
18062         so = static_cast<float>( -sin(ang*pi/180.0) );
18063         sxs = sx*co - sy*so;
18064         sys = sx*so + sy*co;
18065         vector<float> res;
18066         res.push_back(ang);
18067         res.push_back(sxs);
18068         res.push_back(sys);
18069         res.push_back(static_cast<float>(nref));
18070         res.push_back(peak);
18071         return res;
18072 }

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

References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), pi, and Polar2Dm().

17853                                                        {
17854 
17855         size_t crefim_len = crefim.size();
17856 
17857         int   ky = int(2*yrng/step+0.5)/2;
17858         int   kx = int(2*xrng/step+0.5)/2;
17859         float iy, ix;
17860         vector<float> peak(crefim_len*5, -1.0e23f);
17861         for (int i = -ky; i <= ky; i++) {
17862                 iy = i * step ;
17863                 for (int j = -kx; j <= kx; j++) {
17864                         ix = j*step ;
17865                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
17866                         Normalize_ring( cimage, numr );
17867                         Frngs(cimage, numr);
17868                         for (int iref = 0; iref < (int)crefim_len; iref++) {
17869                                 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
17870                                 double qn = retvals["qn"];
17871                                 double qm = retvals["qm"];
17872                                 if(qn >= peak[iref*5] || qm >= peak[iref*5]) {
17873                                         if (qn >= qm) {
17874                                                 peak[iref*5] = static_cast<float>(qn);
17875                                                 peak[iref*5+1] = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
17876                                                 peak[iref*5+2] = -ix;
17877                                                 peak[iref*5+3] = -iy;
17878                                                 peak[iref*5+4] = 0;
17879                                         } else {
17880                                                 peak[iref*5] = static_cast<float>(qm);
17881                                                 peak[iref*5+1] = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
17882                                                 peak[iref*5+2] = -ix;
17883                                                 peak[iref*5+3] = -iy;
17884                                                 peak[iref*5+4] = 1;
17885                                         }
17886                                 }
17887                         }  delete cimage; cimage = 0;
17888                 }
17889         }
17890         for (int iref = 0; iref < (int)crefim_len; iref++) {
17891                 float ang = peak[iref*5+1];
17892                 float sx = peak[iref*5+2];
17893                 float sy = peak[iref*5+3];
17894                 float co =  cos(ang*pi/180.0);
17895                 float so = -sin(ang*pi/180.0);
17896                 float sxs = sx*co - sy*so;
17897                 float sys = sx*so + sy*co;
17898                 peak[iref*5+2] = sxs;
17899                 peak[iref*5+3] = sys;
17900         }
17901         return peak;
17902 }

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

References ang_n(), Crosrng_psi_0_180(), Frngs(), Normalize_ring(), pi, and Polar2Dm().

18276                                                                     {
18277 
18278         size_t crefim_len = crefim.size();
18279 
18280         int   iref, nref=0, mirror=0;
18281         float iy, ix, sx=0, sy=0;
18282         float peak = -1.0E23f;
18283         float ang=0.0f;
18284         int   kx = int(2*xrng/step+0.5)/2;
18285         //if ynumber==-1, use the old code which process x and y direction equally.
18286         if(ynumber==-1) {
18287                 int   ky = int(2*yrng/step+0.5)/2;
18288                 for (int i = -ky; i <= ky; i++) {
18289                         iy = i * step ;
18290                         for (int j = -kx; j <= kx; j++)  {
18291                                 ix = j*step ;
18292                                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18293 
18294                                 Normalize_ring( cimage, numr );
18295 
18296                                 Frngs(cimage, numr);
18297                                 //  compare with all reference images
18298                                 // for iref in xrange(len(crefim)):
18299                                 for ( iref = 0; iref < (int)crefim_len; iref++) {
18300                                         Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18301                                         double qn = retvals["qn"];
18302                                         double qm = retvals["qm"];
18303                                         if(qn >= peak || qm >= peak) {
18304                                                 sx = -ix;
18305                                                 sy = -iy;
18306                                                 nref = iref;
18307                                                 if (qn >= qm) {
18308                                                         ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18309                                                         peak = static_cast<float>(qn);
18310                                                         mirror = 0;
18311                                                 } else {
18312                                                         ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18313                                                         peak = static_cast<float>(qm);
18314                                                         mirror = 1;
18315                                                 }
18316                                         }
18317                                 }  
18318                                 delete cimage; cimage = 0;
18319                         }
18320                    }
18321         }
18322         //if ynumber is given, it should be even. We need to check whether it is zero
18323         else if(ynumber==0) {
18324                 sy = 0.0f;
18325                 for (int j = -kx; j <= kx; j++) {
18326                         ix = j*step ;
18327                         EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode);
18328 
18329                         Normalize_ring( cimage, numr );
18330 
18331                         Frngs(cimage, numr);
18332                         //  compare with all reference images
18333                         // for iref in xrange(len(crefim)):
18334                         for ( iref = 0; iref < (int)crefim_len; iref++)  {
18335                                 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18336                                 double qn = retvals["qn"];
18337                                 double qm = retvals["qm"];
18338                                 if(qn >= peak || qm >= peak) {
18339                                         sx = -ix;
18340                                         nref = iref;
18341                                         if (qn >= qm) {
18342                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18343                                                 peak = static_cast<float>(qn);
18344                                                 mirror = 0;
18345                                         } else {
18346                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18347                                                 peak = static_cast<float>(qm);
18348                                                 mirror = 1;
18349                                         }
18350                                 }
18351                         } 
18352                         delete cimage; cimage = 0;
18353                 }                       
18354         } else {
18355                 int   ky = int(ynumber/2);              
18356                 float stepy=2*yrng/ynumber;
18357                 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl;
18358                 for (int i = -ky+1; i <= ky; i++) {
18359                         iy = i * stepy ;
18360                         for (int j = -kx; j <= kx; j++) {
18361                                 ix = j*step ;
18362                                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18363 
18364                                 Normalize_ring( cimage, numr );
18365 
18366                                 Frngs(cimage, numr);
18367                                 //  compare with all reference images
18368                                 // for iref in xrange(len(crefim)):
18369                                 for ( iref = 0; iref < (int)crefim_len; iref++) {
18370                                         Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18371                                         double qn = retvals["qn"];
18372                                         double qm = retvals["qm"];
18373                                         if(qn >= peak || qm >= peak) {
18374                                                 sx = -ix;
18375                                                 sy = -iy;
18376                                                 nref = iref;
18377                                                 if (qn >= qm) {
18378                                                         ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18379                                                         peak = static_cast<float>(qn);
18380                                                         mirror = 0;
18381                                                 } else {
18382                                                         ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18383                                                         peak = static_cast<float>(qm);
18384                                                         mirror = 1;
18385                                                 }
18386                                         }
18387                                 }
18388                                 delete cimage; cimage = 0;
18389                         }
18390                 }
18391         }
18392         float co, so, sxs, sys;
18393         co = static_cast<float>( cos(ang*pi/180.0) );
18394         so = static_cast<float>( -sin(ang*pi/180.0) );
18395         sxs = sx*co - sy*so;
18396         sys = sx*so + sy*co;
18397         vector<float> res;
18398         res.push_back(ang);
18399         res.push_back(sxs);
18400         res.push_back(sys);
18401         res.push_back(static_cast<float>(mirror));
18402         res.push_back(static_cast<float>(nref));
18403         res.push_back(peak);
18404         return res;
18405 }

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

Definition at line 1032 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 17748 of file util_sparx.cpp.

References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), nn(), sqrt(), and EMAN::EMData::update().

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

17749 {
17750     float* data = ring->get_data();
17751     float av=0.0;
17752     float sq=0.0;
17753     float nn=0.0;
17754     int nring = numr.size()/3;
17755     for( int i=0; i < nring; ++i )
17756     {
17757         int numr3i = numr[3*i+2];
17758         int numr2i = numr[3*i+1]-1;
17759         float w = numr[3*i]*2*M_PI/float(numr[3*i+2]);
17760         for( int j=0; j < numr3i; ++j )
17761         {
17762             int jc = numr2i+j;
17763             av += data[jc] * w;
17764             sq += data[jc] * data[jc] * w;
17765             nn += w;
17766         }
17767     }
17768 
17769     float avg = av/nn;
17770     float sgm = sqrt( (sq-av*av/nn)/nn );
17771     size_t n = (size_t)ring->get_xsize() * ring->get_ysize() * ring->get_zsize();
17772     for( size_t i=0; i < n; ++i )
17773     {
17774         data[i] -= avg;
17775         data[i] /= sgm;
17776     }
17777 
17778     ring->update();
17779 }

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

Definition at line 17658 of file util_sparx.cpp.

References ENTERFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, power(), EMAN::EMData::set_array_offsets(), EMAN::EMData::set_size(), and EMAN::EMData::update().

17659 {
17660         ENTERFUNC;
17661         /* Exception Handle */
17662         if (!img) {
17663                 throw NullPointerException("NULL input image");
17664         }
17665         /* ==============   img is modulus of a complex image in FFT format (so its imaginary parts are zero),
17666                               output is img packed into real image with Friedel part added,   ================ */
17667 
17668         int nxo=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize();
17669         int nx = nxo - 2 + img->is_fftodd();
17670         int lsd2 = (nx + 2 - nx%2) / 2; // Extended x-dimension of the complex image
17671         int nyt, nzt;
17672         int nx2 = nx/2;
17673         int ny2 = ny/2; if(ny2 == 0) nyt =0; else nyt=ny;
17674         int nz2 = nz/2; if(nz2 == 0) nzt =0; else nzt=nz;
17675         int nx2p = nx2+nx%2;
17676         int ny2p = ny2+ny%2;
17677         int nz2p = nz2+nz%2;
17678         EMData& power = *(new EMData()); // output image
17679         power.set_size(nx, ny, nz);
17680         power.set_array_offsets(-nx2,-ny2,-nz2);
17681         //img->set_array_offsets(1,1,1);
17682         float *img_ptr  = img->get_data();
17683         for (int iz = 1; iz <= nz; iz++) {
17684                 int jz=iz-1;
17685                 if(jz>=nz2p) jz=jz-nzt;
17686                 for (int iy = 1; iy <= ny; iy++) {
17687                         int jy=iy-1;
17688                         if(jy>=ny2p) jy=jy-nyt;
17689                         for (int ix = 1; ix <= lsd2; ix++) {
17690                                 int jx=ix-1;
17691                                 if(jx>=nx2p) jx=jx-nx;
17692                                 power(jx,jy,jz) = img_ptr(ix,iy,iz); //real(img->cmplx(ix,iy,iz));
17693                         }
17694                 }
17695         }
17696 //  Create the Friedel related half
17697         int  nzb, nze, nyb, nye, nxb, nxe;
17698         nxb =-nx2+(nx+1)%2;
17699         nxe = nx2-(nx+1)%2;
17700         if(ny2 == 0) {nyb =0; nye = 0;} else {nyb =-ny2+(ny+1)%2; nye = ny2-(ny+1)%2;}
17701         if(nz2 == 0) {nzb =0; nze = 0;} else {nzb =-nz2+(nz+1)%2; nze = nz2-(nz+1)%2;}
17702         for (int iz = nzb; iz <= nze; iz++) {
17703                 for (int iy = nyb; iy <= nye; iy++) {
17704                         for (int ix = 1; ix <= nxe; ix++) { // Note this loop begins with 1 - FFT should create correct Friedel related 0 plane
17705                                 power(-ix,-iy,-iz) = power(ix,iy,iz);
17706                         }
17707                 }
17708         }
17709         if(ny2 != 0)  {
17710                 if(nz2 != 0)  {
17711                         if(nz%2 == 0) {  //if nz even, fix the first slice
17712                                 for (int iy = nyb; iy <= nye; iy++) {
17713                                         for (int ix = nxb; ix <= -1; ix++) {
17714                                                 power(ix,iy,-nz2) = power(-ix,-iy,-nz2);
17715                                         }
17716                                 }
17717                                 if(ny%2 == 0) {  //if ny even, fix the first line
17718                                         for (int ix = nxb; ix <= -1; ix++) {
17719                                                 power(ix,-ny2,-nz2) = power(-ix,-ny2,-nz2);
17720                                         }
17721                                 }
17722                         }
17723                 }
17724                 if(ny%2 == 0) {  //if ny even, fix the first column
17725                         for (int iz = nzb; iz <= nze; iz++) {
17726                                 for (int ix = nxb; ix <= -1; ix++) {
17727                                         power(ix,-ny2,-iz) = power(-ix,-ny2,iz);
17728                                 }
17729                         }
17730                 }
17731 
17732         }
17733         power.update();
17734         power.set_array_offsets(0,0,0);
17735         return &power;
17736 }

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

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

05265 {
05266         /* Exception Handle */
05267         if (!img)  throw NullPointerException("NULL input image");
05268         /* ============================== */
05269 
05270         // Get the size of the input image
05271         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
05272         /* ============================== */
05273 
05274         /* Exception Handle */
05275         if(new_nx<nx || new_ny<ny || new_nz<nz)
05276                 throw ImageDimensionException("The size of the padded image cannot be lower than the input image size.");
05277         if((new_nx/2)-(nx/2)+x_offset<0 || (new_ny/2)-(ny/2)+y_offset<0 || (new_nz/2)-(nz/2)+z_offset<0)
05278                 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters");
05279         if(x_offset>((new_nx-(new_nx/2))-(nx-(nx/2))) || y_offset>((new_ny-(new_ny/2))-(ny-(ny/2))) || z_offset>((new_nz-(new_nz/2))-(nz-(nz/2))))
05280                 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters");
05281         /* ============================== */
05282 
05283         EMData* pading = img->copy_head();
05284         pading->set_size(new_nx, new_ny, new_nz);
05285         float *inp  = img->get_data();
05286         float *outp = pading->get_data();
05287 
05288 
05289         /* Calculation of the average and the circumference values for background substitution
05290         =======================================================================================*/
05291         float background;
05292 
05293         if (strcmp(params,"average")==0) background = img->get_attr("mean");
05294         else if (strcmp(params,"circumference")==0) {
05295                 float sum1=0.0f;
05296                 size_t cnt=0;
05297                 for(int i=0;i<nx;i++) {
05298                         sum1 += inp(i,0,0) + inp(i,ny-1,nz-1);
05299                         cnt+=2;
05300                 }
05301                 if(nz-1 == 0) {
05302                         for (int j=1;j<ny-1;j++) {
05303                                 sum1 += inp(1,j,0) + inp(nx-1,j,0);
05304                                 cnt+=2;
05305                         }
05306                 } else {
05307                         for (int k=1;k<nz-1;k++) {
05308                                 for (int j=1;j<ny-1;j++) {
05309                                         sum1 += inp(1,j,0) + inp(nx-1,j,0);
05310                                         cnt+=2;
05311                                 }
05312                         }
05313                 }
05314                 background = sum1/cnt;
05315         } else {
05316                 background = static_cast<float>( atof( params ) );
05317         }
05318         /*=====================================================================================*/
05319 
05320          /*Initial Padding */
05321         int new_st_x=0,new_st_y=0,new_st_z=0;
05322         for (int k=0;k<new_nz;k++)
05323                 for(int j=0;j<new_ny;j++)
05324                         for (int i=0;i<new_nx;i++)
05325                                 outp(i,j,k)=background;
05326         /*============================== */
05327 
05328         /*    Calculation of the start point */
05329         new_st_x=int((new_nx/2-nx/2)  + x_offset);
05330         new_st_y=int((new_ny/2-ny/2)  + y_offset);
05331         new_st_z=int((new_nz/2-nz/2)  + z_offset);
05332         /* ============================== */
05333 
05334         for (int k=0;k<nz;k++)
05335                 for(int j=0;j<ny;j++)
05336                         for(int i=0;i<nx;i++)
05337                                 outp(i,j,k)=inp(i,j,k);
05338         pading->update();
05339         return pading;
05340 }

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

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(), EMAN::Transform::ERR_LIMIT, t, and v.

Referenced by point_is_in_convex_polygon_2d().

01235 {
01236 
01237         Vec2f u = p2 - p1;
01238         Vec2f v = p3 - p1;
01239         Vec2f w = point - p1;
01240 
01241         float udotu = u.dot(u);
01242         float udotv = u.dot(v);
01243         float udotw = u.dot(w);
01244         float vdotv = v.dot(v);
01245         float vdotw = v.dot(w);
01246 
01247         float d = 1.0f/(udotv*udotv - udotu*vdotv);
01248         float s = udotv*vdotw - vdotv*udotw;
01249         s *= d;
01250 
01251         float t = udotv*udotw - udotu*vdotw;
01252         t *= d;
01253 
01254         // We've done a few multiplications, so detect when there are tiny residuals that may throw off the final
01255         // decision
01256         if (fabs(s) < Transform::ERR_LIMIT ) s = 0;
01257         if (fabs(t) < Transform::ERR_LIMIT ) t = 0;
01258 
01259         if ( fabs((fabs(s)-1.0)) < Transform::ERR_LIMIT ) s = 1;
01260         if ( fabs((fabs(t)-1.0)) < Transform::ERR_LIMIT ) t = 1;
01261 
01262 //      cout << "s and t are " << s << " " << t << endl;
01263 
01264         // The final decision, if this is true then we've hit the jackpot
01265         if ( s >= 0 && t >= 0 && (s+t) <= 1 ) return true;
01266         else return false;
01267 }

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(), 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(), xim, and y.

Referenced by ali2d_ccf_list(), multiref_peaks_ali2d(), multiref_peaks_compress_ali2d(), multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), and multiref_polar_ali_helical().

02221                                                                                            {
02222         int nsam = image->get_xsize();
02223         int nrow = image->get_ysize();
02224         int nring = numr.size()/3;
02225         int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
02226         EMData* out = new EMData();
02227         out->set_size(lcirc,1,1);
02228         char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h';
02229         float *xim  = image->get_data();
02230         float *circ = out->get_data();
02231         double dpi, dfi;
02232         int    it, jt, inr, l, nsim, kcirc, lt;
02233         float  xold, yold, fi, x, y;
02234 
02235         //     cns2 and cnr2 are predefined centers
02236         //     no need to set to zero, all elements are defined
02237         dpi = 2*atan(1.0);
02238         for (it=1; it<=nring; it++) {
02239                 // radius of the ring
02240                 inr = numr(1,it);
02241 
02242                 // "F" means a full circle interpolation
02243                 // "H" means a half circle interpolation
02244 
02245                 l = numr(3,it);
02246                 if ( mode == 'h' || mode == 'H' ) lt = l / 2;
02247                 else                              lt = l / 4;
02248 
02249                 nsim  = lt - 1;
02250                 dfi   = dpi / (nsim+1);
02251                 kcirc = numr(2,it);
02252                 xold  = 0.0f+cns2;
02253                 yold  = inr+cnr2;
02254 
02255                 Assert( kcirc <= lcirc );
02256                 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim);    // Sampling on 90 degree
02257 
02258                 xold  = inr+cns2;
02259                 yold  = 0.0f+cnr2;
02260                 Assert( lt+kcirc <= lcirc );
02261                 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);  // Sampling on 0 degree
02262 
02263                 if ( mode == 'f' || mode == 'F' ) {
02264                         xold = 0.0f+cns2;
02265                         yold = -inr+cnr2;
02266                         Assert( lt+lt+kcirc <= lcirc );
02267                         circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);  // Sampling on 270 degree
02268 
02269                         xold = -inr+cns2;
02270                         yold = 0.0f+cnr2;
02271                         Assert(lt+lt+lt+kcirc <= lcirc );
02272                         circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 180 degree
02273                 }
02274 
02275                 for (jt=1; jt<=nsim; jt++) {
02276                         fi   = static_cast<float>(dfi * jt);
02277                         x    = sin(fi) * inr;
02278                         y    = cos(fi) * inr;
02279 
02280                         xold = x+cns2;
02281                         yold = y+cnr2;
02282 
02283                         Assert( jt+kcirc <= lcirc );
02284                         circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim);      // Sampling on the first quadrant
02285 
02286                         xold = y+cns2;
02287                         yold = -x+cnr2;
02288 
02289                         Assert( jt+lt+kcirc <= lcirc );
02290                         circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);    // Sampling on the fourth quadrant
02291 
02292                         if ( mode == 'f' || mode == 'F' ) {
02293                                 xold = -x+cns2;
02294                                 yold = -y+cnr2;
02295 
02296                                 Assert( jt+lt+lt+kcirc <= lcirc );
02297                                 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the third quadrant
02298 
02299                                 xold = -y+cns2;
02300                                 yold = x+cnr2;
02301 
02302                                 Assert( jt+lt+lt+lt+kcirc <= lcirc );
02303                                 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);  // Sampling on the second quadrant
02304                         }
02305                 } // end for jt
02306         } //end for it
02307         return out;
02308 }

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(), 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(), 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 6241 of file util_sparx.cpp.

References call_cl1(), log(), and q.

06242 {
06243         int k,m,n1,klmd,klm2d,nklmd,n2d,n_larg,l, n2;
06244 
06245         k=(int)pw.size();
06246         l=0;
06247         m=k;
06248         n2=n+2;
06249         n1=n+1;
06250         klmd=k+l+m;
06251         klm2d= k+l+m+2;
06252         nklmd=k+l+m+n;
06253         n2d=n+2;
06254         /*size has to be increased when N is large*/
06255         n_larg=klmd*2;
06256         klm2d=n_larg+klm2d;
06257         klmd=n_larg+klmd;
06258         nklmd=n_larg+nklmd;
06259         int size_q=klm2d*n2d;
06260         int size_cu=nklmd*2;
06261         static int i__;
06262 
06263          double *q ;
06264          double *x ;
06265          double *res;
06266          double *cu;
06267          float *q2;
06268          float *pw_;
06269          long int *iu;
06270          double *s;
06271          q = (double*)calloc(size_q,sizeof(double));
06272          x = (double*)calloc(n2d,sizeof(double));
06273          res = (double*)calloc(klmd,sizeof(double));
06274          cu =(double*)calloc(size_cu,sizeof(double));
06275          s = (double*)calloc(klmd,sizeof(double));
06276          q2 = (float*)calloc(size_q,sizeof(float));
06277          iu = (long int*)calloc(size_cu,sizeof(long int));
06278          pw_ = (float*)calloc(k,sizeof(float));
06279 
06280         for( i__ =0;i__<k;++i__)
06281                 {
06282                 pw_[i__]=log(pw[i__]); }
06283         long int l_k=k;
06284         long int l_n=n;
06285         long int l_iswi=iswi;
06286         vector<float> cl1_res;
06287         cl1_res=Util::call_cl1(&l_k, &l_n, &ps, &l_iswi, pw_, q2, q, x, res, cu, s, iu);
06288         free(q);
06289         free(x);
06290         free(res);
06291         free(s);
06292         free(cu);
06293         free(q2);
06294         free(iu);
06295         free(pw_);
06296         return cl1_res;
06297 }

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:

Mesh spacings: 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, x, and y.

Referenced by alrl_ms(), Polar2D(), Polar2Dm(), quadri_background(), and EMAN::EMData::rot_scale_trans2D().

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:

Mesh spacings: 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.

Referenced by EMAN::EMData::rot_scale_trans2D_background().

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

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, img_ptr, new_ptr, nx, ny, EMAN::EMData::set_size(), and EMAN::EMData::update().

Referenced by EMAN::PCA::dopca(), and EMAN::PCA::dopca_lan().

06073 {
06074         /********
06075         ***Exception Handle
06076         *************/
06077         if(mask == NULL)
06078                 throw ImageDimensionException("The mask cannot be an null image");
06079 
06080         /***********
06081         ***get the size of the mask
06082         **************/
06083         int nx = mask->get_xsize(),ny = mask->get_ysize(),nz = mask->get_zsize();
06084 
06085         size_t i,size = (size_t)nx*ny*nz;                        /* loop counters */
06086         /* new image declaration */
06087         EMData *new_image = new EMData();
06088         new_image->set_size(nx,ny,nz);           /* set the size of new image */
06089         float *new_ptr  = new_image->get_data(); /* set size of the new image */
06090         float *mask_ptr = mask->get_data();      /* assign a pointer to the mask image */
06091         float *img_ptr  = image->get_data();     /* assign a pointer to the 1D image */
06092         int count = 0;
06093         float sum_under_mask = 0.0 ;
06094         for(i = 0;i < size;i++){
06095                         if(mask_ptr[i] > 0.5f){
06096                                 new_ptr[i] = img_ptr[count];
06097                                 sum_under_mask += img_ptr[count];
06098                                 count++;
06099                                 if( count > image->get_xsize() ) {
06100                                     throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too large");
06101                                 }
06102                         }
06103         }
06104 
06105         if( count > image->get_xsize() ) {
06106             throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too small");
06107         }
06108 
06109         float avg_under_mask = sum_under_mask / count;
06110         for(i = 0;i < size;i++) {
06111                 if(mask_ptr[i] <= 0.5f)  new_ptr[i] = avg_under_mask;
06112         }
06113         new_image->update();
06114         return new_image;
06115 }

string Util::recv_broadcast ( int  port  )  [static]

Definition at line 1041 of file util.cpp.

References BPKT::data, BPKT::hdr, EMAN::ByteOrder::is_host_big_endian(), BPKT::len, BPKT::oseq, and BPKT::pseq.

01041                                     {
01042 //      struct sockaddr_in sadr = { AF_INET, 9989, INADDR_ANY};
01043 //      int sock=socket(AF_INET,SOCK_DGRAM,0);
01044 //      if (bind(sock,&sadr,sizeof(sockaddr_in))) return string();
01045 
01046         if (ByteOrder::is_host_big_endian()) {
01047                 printf("No cache mirroring on Big endian machines yet\n");
01048                 return string();        // FIXME: no support for big endian hosts
01049         }
01050 
01051         BPKT pkt;
01052         string ret;
01053         vector<char> fill;
01054         int obj=-1;
01055         unsigned int i=0;
01056 //      printf ("Listening\n");
01057 
01058         while (1) {
01059                 int l = recv(sock,&pkt,1044,0);
01060                 if (l<=0) {
01061                         if (obj!=-1) printf("Timeout with incomplete obj %d  %d/%d\n",obj,i,(int)fill.size());
01062                         return string();                // probably a timeout
01063                 }
01064                 if (l<20) {
01065                         printf("Bad packet from broadcast");
01066                         continue;
01067                 }
01068 
01069                 if (strncmp(pkt.hdr,"EMAN",4)!=0) continue;
01070 
01071                 // new object coming in
01072                 if (obj!=pkt.oseq) {
01073                         obj=pkt.oseq;
01074                         ret.resize(pkt.len);
01075                         fill.resize((pkt.len-1)/1024+1);
01076                         for (i=0; i<fill.size(); i++) fill[i]=0;
01077                 }
01078                 if (obj==-1) printf("Something wierd happened. please report\n");
01079 
01080                 // copy the packet into the output buffer
01081                 fill[pkt.pseq]=1;
01082                 ret.replace(pkt.pseq*1024,l-20,(char *)pkt.data,l-20);
01083 
01084                 // see if we got everything
01085                 for (i=0; i<fill.size(); i++) {
01086                         if (fill[i]!=1) break;
01087                 }
01088 //              printf("\t\t\tObj %d  %d/%d      \r",obj,i,(int)fill.size());
01089                 fflush(stdout);
01090 
01091                 if (i==fill.size()) return ret;         // Yea !  We got a good packet
01092         }
01093 
01094 }

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

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

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 }

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

Definition at line 1082 of file util.h.

Referenced by get_pixel_conv_new(), and get_pixel_conv_new_background().

01095                                             {

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

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

00096 {
00097         if(ny==1 && nz==1) {    //1D, do nothing
00098                 return;
00099         }
00100         else if(ny!=1 && nz==1) {       //2D, rotate vertically by ny/2
00101                 size_t i, j, k, l;
00102                 float re;
00103                 l=ny/2*nx;
00104                 for (i=0; i<ny/2; i++) {
00105                         for (j=0; j<nx; j++) {
00106                                 k=j+i*nx;
00107                                 re=data[k];
00108                                 data[k]=data[k+l];
00109                                 data[k+l]=re;
00110                         }
00111                 }
00112         }
00113         else {  //3D, in the y,z plane, swaps quadrants I,III and II,IV, this is the 'rotation' in y and z
00114                 size_t i, j, k, l, ii, jj;
00115                 char * t=(char *)malloc(sizeof(float)*nx);
00116 
00117                 k=nx*ny*(nz+1)/2;
00118                 l=nx*ny*(nz-1)/2;
00119                 jj=nx*sizeof(float);
00120                 for (j=ii=0; j<nz/2; ++j) {
00121                         for (i=0; i<ny; ++i,ii+=nx) {
00122                                 memcpy(t,data+ii,jj);
00123                                 if (i<ny/2) {
00124                                         memcpy(data+ii,data+ii+k,jj);
00125                                         memcpy(data+ii+k,t,jj);
00126                                 }
00127                                 else {
00128                                         memcpy(data+ii,data+ii+l,jj);
00129                                         memcpy(data+ii+l,t,jj);
00130                                 }
00131                         }
00132                 }
00133                 free(t);
00134         }
00135 }

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

Get ceiling round of a float number x.

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

Definition at line 1454 of file util.h.

static 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 1442 of file util.h.

Referenced by EMAN::Util::FakeKaiserBessel::build_I0table(), EMAN::Util::KaiserBessel::build_I0table(), EMAN::Util::sincBlackman::build_sBtable(), EMAN::EMData::calc_fourier_shell_correlation(), EMAN::EMData::calc_hist(), EMAN::EMData::cog(), EMAN::EMData::cut_slice(), EMAN::EMData::extract_plane(), EMAN::EMData::extract_plane_rect(), EMAN::EMData::extract_plane_rect_fast(), EMAN::EMData::extractline(), EMAN::EMData::extractpoint(), extractpoint2(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), EMAN::EMData::get_pixel_conv(), get_pixel_conv_new(), get_pixel_conv_new_background(), EMAN::EMData::get_pixel_filtered(), hypot_fast_int(), EMAN::EMData::phase_cog(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), EMAN::BeamstopProcessor::process_inplace(), EMAN::EMData::rot_scale_conv(), EMAN::EMData::rot_scale_conv7(), EMAN::EMData::translate(), and EMAN::EMData::uncut_slice().

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

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

Definition at line 20204 of file util_sparx.cpp.

References k_means_cont_table_().

20204                                                                                                          {
20205         //cout<<"sanitycheck called\n";
20206         int total_cost = *output;
20207         int num_matches = *(output+1);
20208 
20209         int cost=0;
20210         int* intx;
20211         int intx_size;
20212         int* intx_next(0);
20213         int intx_next_size = 0;
20214         int curclass;
20215         int curclass_size;
20216         //cout<<"cost by match: [";
20217         for(int i = 0; i < num_matches; i++){
20218                 curclass = *(output+2+ i*nParts);
20219                 // check feasibility
20220                 if (*(argParts + Indices[curclass]+1) == -5) {cout<<"infeasible match!\n"; return 0;}
20221                 *(argParts + Indices[curclass]+1) = -5;
20222                 // initialize intx to the number of elements in class curclass of partition 0 of the i-th match
20223                 curclass_size = *(dimClasses+curclass)-2;
20224                 intx = new int[curclass_size];
20225                 for (int ic = 0; ic < curclass_size; ic++) *(intx+ic) = *(argParts + Indices[curclass]+2+ic);
20226                 intx_size = curclass_size;
20227 
20228                 for (int j=1; j < nParts; j++){
20229                       curclass = *(output+2+ i*nParts+j);
20230                       if (*(argParts + Indices[j*K+curclass]+1)==-5){cout<<"infeasible match!\n"; return 0;}
20231                       *(argParts + Indices[j*K+curclass]+1)=-5;
20232                       // compute the intersection of intx and class curclass of partition j of the i-th match
20233                       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);
20234                       intx_next = new int[intx_next_size];
20235                       Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,1);
20236                       delete[] intx;
20237                       intx=intx_next;
20238                       intx_size= intx_next_size;
20239                       if (j==nParts-1) delete[] intx_next;
20240                 }
20241 
20242                 if (intx_next_size <= T) {cout << "something wrong with solution!\n"; return 0;}
20243                 //cout <<intx_next_size<<",";
20244                 cost = cost + intx_next_size;
20245         }
20246         //cout<<"]\n";
20247         if (cost != total_cost) {cout << "something wrong with solution!\n"; return 0;}
20248 
20249         return 1;
20250 
20251 }

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::MatchSFProcessor::create_radial_func(), EMAN::LowpassAutoBProcessor::create_radial_func(), and EMAN::CtfAverager::finish().

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

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

Get a filename's basename.

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

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

References explore2(), and k_means_cont_table_().

20258                                                                                                                               {
20259         
20260         // some temp variables
20261         bool flag = 0;
20262         int nintx;
20263         int* dummy(0);
20264         //int* ret;
20265         int* curbranch = new int[nParts];
20266         
20267         //initialize costlist to all 0
20268         for(int jit= 0; jit< J; jit++) *(costlist+jit) = 0;
20269         
20270         
20271         for(int a=0; a<K; a++)
20272         {
20273         
20274                 // 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
20275                 if (*(argParts + Indices[a] + 1) < 1) continue;
20276                 if (*(dimClasses + a)-2 <= T) continue;
20277 
20278                 // 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
20279 
20280                 for( int i=1; i < nParts; i++){
20281                         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.
20282                         for(int j=0; j < K; j++){
20283                                 if (*(argParts + Indices[i*K+j] + 1) < 1) continue;
20284                                 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);
20285                                 if (nintx > T) flag=1;
20286                                 else *(argParts + Indices[i*K+j] + 1) =-4;
20287                         }
20288                         if (flag==0) {break;}
20289                 }
20290 
20291                 // explore determines J matchs with the largest weight greater than T where class in partition 0 is class a
20292                 *curbranch = a;
20293 
20294                 if (flag > 0) // Each partition has one or more active class
20295                         Util::explore2(argParts, Indices, dimClasses, nParts, K, T, argParts+Indices[a]+2, *(dimClasses+a)-2, argParts+Indices[a]+2,
20296                         *(dimClasses+a)-2,0, J, matchlist, costlist, curbranch);
20297                         
20298                 // take all the classes marked as -4 and remark it as 1 in preparation for next round
20299                 for( int i=1; i < nParts; i++){
20300                         for(int j=0; j < K; j++){
20301                                 if (*(argParts + Indices[i*K+j] + 1) == -4) *(argParts + Indices[i*K+j] + 1) =1;
20302 
20303                         }
20304                 }
20305         }
20306         
20307         delete[] curbranch;
20308 }

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

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

04665 {
04666         int i;
04667         int nx=img->get_xsize();
04668         float *img_ptr  = img->get_data();
04669         float *line_ptr = line->get_data();
04670         for (i=0;i<length;i++) img_ptr[nx*posline + i] = line_ptr[offset + i];
04671         img->update();
04672 }

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.

References EMAN::Log::logger(), and EMAN::Log::set_level().

01109 {
01110         if (argc > 1 && strncmp(argv[1], "-v", 2) == 0) {
01111                 char level_str[32];
01112                 strcpy(level_str, argv[1] + 2);
01113                 Log::LogLevel log_level = (Log::LogLevel) atoi(level_str);
01114                 Log::logger()->set_level(log_level);
01115         }
01116 }

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

Set the seed for Randnum class.

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

Definition at line 678 of file util.cpp.

References EMAN::Randnum::Instance(), and EMAN::Randnum::set_seed().

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

template<class T>
static 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 2064 of file util.h.

Referenced by EMAN::EMData::extract_plane(), EMAN::EMData::extract_plane_rect(), EMAN::EMData::extract_plane_rect_fast(), EMAN::EMData::extractline(), fftc_d(), fftc_q(), and EMAN::EMData::getconvpt2d_kbi0().

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

Definition at line 5358 of file util_sparx.cpp.

References colreverse().

Referenced by cyclicshift().

05359 {
05360         int nxy = nx*ny;
05361         colreverse(beg, end, nxy);
05362 }

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.

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

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 }

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

Calculate a number's square.

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

Definition at line 1582 of file util.h.

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

Calculate a number's square.

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

Definition at line 1573 of file util.h.

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

Calculate a number's square.

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

Definition at line 1564 of file util.h.

Referenced by EMAN::EMData::calc_dist(), EMAN::EMData::calc_mutual_correlation(), EMAN::EMData::calc_sigma_diff(), EMAN::OptVarianceCmp::cmp(), EMAN::EMData::do_radon(), get_stats_cstyle(), EMAN::EMData::little_big_dot(), EMAN::SmartMaskProcessor::process_inplace(), and EMAN::PaintProcessor::process_inplace().

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

Calcuate (x*x + y*y).

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

Definition at line 1592 of file util.h.

Referenced by EMAN::EMData::common_lines(), get_stats(), and get_stats_cstyle().

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

Safe string compare.

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

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

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::Symmetry3D::get_symmetries(), EMAN::Dict::has_key_ci(), and EMAN::Transform::set_rotation().

00241                                          {
00242         string ret(s);
00243         std::transform(s.begin(),s.end(),ret.begin(), (int (*)(int) ) std::tolower);
00244         return ret;
00245 }

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

Definition at line 4507 of file util_sparx.cpp.

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

04507                                                                                       {
04508         int nring = numr.size()/3;
04509         float *ave = avep->get_data();
04510         float *dat = datp->get_data();
04511         int i, j, numr3i, np;
04512         float  arg, cs, si;
04513         int maxrin = numr(3,nring);
04514         if(mirror == 1) { //for mirrored data has to be conjugated
04515                 for (i=1; i<=nring; i++) {
04516                         numr3i = numr(3,i);
04517                         np     = numr(2,i)-1;
04518                         ave[np]   -= dat[np];
04519                         ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04520                         for (j=2; j<numr3i; j=j+2) {
04521                                 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04522                                 cs = cos(arg);
04523                                 si = sin(arg);
04524                                 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04525                                 ave[np + j]    -= dat[np + j]*cs - dat[np + j +1]*si;
04526                                 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs;
04527                         }
04528                 }
04529         } else {
04530                 for (i=1; i<=nring; i++) {
04531                         numr3i = numr(3,i);
04532                         np     = numr(2,i)-1;
04533                         ave[np]   -= dat[np];
04534                         ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04535                         for (j=2; j<numr3i; j=j+2) {
04536                                 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04537                                 cs = cos(arg);
04538                                 si = sin(arg);
04539                                 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04540                                 ave[np + j]    -= dat[np + j]*cs - dat[np + j +1]*si;
04541                                 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs;
04542                         }
04543                 }
04544         }
04545         avep->update();
04546         EXITFUNC;
04547 }

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

Definition at line 17553 of file util_sparx.cpp.

References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update().

17554 {
17555         ENTERFUNC;
17556         /* Exception Handle */
17557         if (!img) {
17558                 throw NullPointerException("NULL input image");
17559         }
17560         /* ========= img -= img1 ===================== */
17561 
17562         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17563         size_t size = (size_t)nx*ny*nz;
17564         float *img_ptr  = img->get_data();
17565         float *img1_ptr = img1->get_data();
17566         for (size_t i=0;i<size;++i) img_ptr[i] -= img1_ptr[i];
17567         img->update();
17568 
17569         EXITFUNC;
17570 }

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

Definition at line 17335 of file util_sparx.cpp.

References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update().

17336 {
17337         ENTERFUNC;
17338         /* Exception Handle */
17339         if (!img) {
17340                 throw NullPointerException("NULL input image");
17341         }
17342         /* ==============   output = img - img1   ================ */
17343 
17344         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17345         size_t size = (size_t)nx*ny*nz;
17346         EMData * img2 = img->copy_head();
17347         float *img_ptr  =img->get_data();
17348         float *img2_ptr = img2->get_data();
17349         float *img1_ptr = img1->get_data();
17350         for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] - img1_ptr[i];
17351         img2->update();
17352         if(img->is_complex()) {
17353                 img2->set_complex(true);
17354                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17355         }
17356 
17357         EXITFUNC;
17358         return img2;
17359 }

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 copy_head(), get_value_at(), EMAN::EMData::set_value_at(), V, x, X, and y.

Referenced by EMAN::PCA::dopca().

00288                                                                    {
00289         int nimg=data.size();
00290         if (nvec==0) nvec=nimg;
00291         vector<EMData *> ret(nvec);
00292         if (nimg==0) return ret;
00293         int pixels=data[0]->get_xsize()*data[0]->get_ysize()*data[0]->get_zsize();
00294 
00295         // Allocate the working space
00296         gsl_vector *work=gsl_vector_alloc(nimg);
00297         gsl_vector *S=gsl_vector_alloc(nimg);
00298         gsl_matrix *A=gsl_matrix_alloc(pixels,nimg);
00299         gsl_matrix *V=gsl_matrix_alloc(nimg,nimg);
00300         gsl_matrix *X=gsl_matrix_alloc(nimg,nimg);
00301 
00302         int im,x,y,z,i;
00303         for (im=0; im<nimg; im++) {
00304                 for (z=0,i=0; z<data[0]->get_zsize(); z++) {
00305                         for (y=0; y<data[0]->get_ysize(); y++) {
00306                                 for (x=0; x<data[0]->get_xsize(); x++,i++) {
00307                                         gsl_matrix_set(A,i,im,data[im]->get_value_at(x,y,z));
00308                                 }
00309                         }
00310                 }
00311         }
00312 
00313         // This calculates the SVD
00314         gsl_linalg_SV_decomp_mod (A,X, V, S, work);
00315 
00316         for (im=0; im<nvec; im++) {
00317                 EMData *a=data[0]->copy_head();
00318                 ret[im]=a;
00319                 for (z=0,i=0; z<data[0]->get_zsize(); z++) {
00320                         for (y=0; y<data[0]->get_ysize(); y++) {
00321                                 for (x=0; x<data[0]->get_xsize(); x++,i++) {
00322                                         a->set_value_at(x,y,z,static_cast<float>(gsl_matrix_get(A,i,im)));
00323                                 }
00324                         }
00325                 }
00326         }
00327         return ret;
00328 }

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

Definition at line 6020 of file util_sparx.cpp.

References phase(), and sqrt().

Referenced by ctf_img().

06021 {
06022         float cst  = cs*1.0e7f;
06023 
06024         wgh /= 100.0;
06025         float phase = atan(wgh/sqrt(1.0f-wgh*wgh));
06026         float lambda=12.398f/sqrt(voltage*(1022.0f+voltage));
06027         float ak2 = ak*ak;
06028         float g1 = dzz*1.0e4f*lambda*ak2;
06029         float g2 = cst*lambda*lambda*lambda*ak2*ak2/2.0f;
06030 
06031         float ctfv = static_cast<float>( sin(M_PI*(g1-g2)+phase)*sign );
06032         if(b_factor != 0.0f)  ctfv *= exp(-b_factor*ak2/4.0f);
06033 
06034         return ctfv;
06035 }

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

Calculate trilinear interpolation.

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 1503 of file util.h.

Referenced by EMAN::EMData::cut_slice(), 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.

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

References abs, addnod_(), and left_().

07776 {
07777     /* System generated locals */
07778     int i__1, i__2;
07779 
07780     /* Local variables */
07781     static double d__;
07782     static int i__, j;
07783     static double d1, d2, d3;
07784     static int i0, lp, kt, ku, lpl, nku;
07785     extern long int left_(double *, double *, double *, double
07786             *, double *, double *, double *, double *,
07787             double *);
07788     static int nexti;
07789     extern /* Subroutine */ int addnod_(int *, int *, double *,
07790             double *, double *, int *, int *, int *,
07791             int *, int *);
07792 
07793 
07794 /* *********************************************************** */
07795 
07796 /*                                              From STRIPACK */
07797 /*                                            Robert J. Renka */
07798 /*                                  Dept. of Computer Science */
07799 /*                                       Univ. of North Texas */
07800 /*                                           renka@cs.unt.edu */
07801 /*                                                   01/20/03 */
07802 
07803 /*   This is an alternative to TRMESH with the inclusion of */
07804 /* an efficient means of removing duplicate or nearly dupli- */
07805 /* cate nodes. */
07806 
07807 /*   This subroutine creates a Delaunay triangulation of a */
07808 /* set of N arbitrarily distributed points, referred to as */
07809 /* nodes, on the surface of the unit sphere.  Refer to Sub- */
07810 /* routine TRMESH for definitions and a list of additional */
07811 /* subroutines.  This routine is an alternative to TRMESH */
07812 /* with the inclusion of an efficient means of removing dup- */
07813 /* licate or nearly duplicate nodes. */
07814 
07815 /*   The algorithm has expected time complexity O(N*log(N)) */
07816 /* for random nodal distributions. */
07817 
07818 
07819 /* On input: */
07820 
07821 /*       N0 = Number of nodes, possibly including duplicates. */
07822 /*            N0 .GE. 3. */
07823 
07824 /*       TOL = Tolerance defining a pair of duplicate nodes: */
07825 /*             bound on the deviation from 1 of the cosine of */
07826 /*             the angle between the nodes.  Note that */
07827 /*             |1-cos(A)| is approximately A*A/2. */
07828 
07829 /* The above parameters are not altered by this routine. */
07830 
07831 /*       X,Y,Z = Arrays of length at least N0 containing the */
07832 /*               Cartesian coordinates of nodes.  (X(K),Y(K), */
07833 /*               Z(K)) is referred to as node K, and K is re- */
07834 /*               ferred to as a nodal index.  It is required */
07835 /*               that X(K)**2 + Y(K)**2 + Z(K)**2 = 1 for all */
07836 /*               K.  The first three nodes must not be col- */
07837 /*               linear (lie on a common great circle). */
07838 
07839 /*       LIST,LPTR = Arrays of length at least 6*N0-12. */
07840 
07841 /*       LEND = Array of length at least N0. */
07842 
07843 /*       INDX = Array of length at least N0. */
07844 
07845 /*       LCNT = Array of length at least N0 (length N is */
07846 /*              sufficient). */
07847 
07848 /*       NEAR,NEXT,DIST = Work space arrays of length at */
07849 /*                        least N0.  The space is used to */
07850 /*                        efficiently determine the nearest */
07851 /*                        triangulation node to each un- */
07852 /*                        processed node for use by ADDNOD. */
07853 
07854 /* On output: */
07855 
07856 /*       N = Number of nodes in the triangulation.  3 .LE. N */
07857 /*           .LE. N0, or N = 0 if IER < 0. */
07858 
07859 /*       X,Y,Z = Arrays containing the Cartesian coordinates */
07860 /*               of the triangulation nodes in the first N */
07861 /*               locations.  The original array elements are */
07862 /*               shifted down as necessary to eliminate dup- */
07863 /*               licate nodes. */
07864 
07865 /*       LIST = Set of nodal indexes which, along with LPTR, */
07866 /*              LEND, and LNEW, define the triangulation as a */
07867 /*              set of N adjacency lists -- counterclockwise- */
07868 /*              ordered sequences of neighboring nodes such */
07869 /*              that the first and last neighbors of a bound- */
07870 /*              ary node are boundary nodes (the first neigh- */
07871 /*              bor of an interior node is arbitrary).  In */
07872 /*              order to distinguish between interior and */
07873 /*              boundary nodes, the last neighbor of each */
07874 /*              boundary node is represented by the negative */
07875 /*              of its index. */
07876 
07877 /*       LPTR = Set of pointers (LIST indexes) in one-to-one */
07878 /*              correspondence with the elements of LIST. */
07879 /*              LIST(LPTR(I)) indexes the node which follows */
07880 /*              LIST(I) in cyclical counterclockwise order */
07881 /*              (the first neighbor follows the last neigh- */
07882 /*              bor). */
07883 
07884 /*       LEND = Set of pointers to adjacency lists.  LEND(K) */
07885 /*              points to the last neighbor of node K for */
07886 /*              K = 1,...,N.  Thus, LIST(LEND(K)) < 0 if and */
07887 /*              only if K is a boundary node. */
07888 
07889 /*       LNEW = Pointer to the first empty location in LIST */
07890 /*              and LPTR (list length plus one).  LIST, LPTR, */
07891 /*              LEND, and LNEW are not altered if IER < 0, */
07892 /*              and are incomplete if IER > 0. */
07893 
07894 /*       INDX = Array of output (triangulation) nodal indexes */
07895 /*              associated with input nodes.  For I = 1 to */
07896 /*              N0, INDX(I) is the index (for X, Y, and Z) of */
07897 /*              the triangulation node with the same (or */
07898 /*              nearly the same) coordinates as input node I. */
07899 
07900 /*       LCNT = Array of int weights (counts) associated */
07901 /*              with the triangulation nodes.  For I = 1 to */
07902 /*              N, LCNT(I) is the number of occurrences of */
07903 /*              node I in the input node set, and thus the */
07904 /*              number of duplicates is LCNT(I)-1. */
07905 
07906 /*       NEAR,NEXT,DIST = Garbage. */
07907 
07908 /*       IER = Error indicator: */
07909 /*             IER =  0 if no errors were encountered. */
07910 /*             IER = -1 if N0 < 3 on input. */
07911 /*             IER = -2 if the first three nodes are */
07912 /*                      collinear. */
07913 /*             IER = -3 if Subroutine ADDNOD returns an error */
07914 /*                      flag.  This should not occur. */
07915 
07916 /* Modules required by TRMSH3:  ADDNOD, BDYADD, COVSPH, */
07917 /*                                INSERT, INTADD, JRAND, */
07918 /*                                LEFT, LSTPTR, STORE, SWAP, */
07919 /*                                SWPTST, TRFIND */
07920 
07921 /* Intrinsic function called by TRMSH3:  ABS */
07922 
07923 /* *********************************************************** */
07924 
07925 
07926 /* Local parameters: */
07927 
07928 /* D =        (Negative cosine of) distance from node KT to */
07929 /*              node I */
07930 /* D1,D2,D3 = Distances from node KU to nodes 1, 2, and 3, */
07931 /*              respectively */
07932 /* I,J =      Nodal indexes */
07933 /* I0 =       Index of the node preceding I in a sequence of */
07934 /*              unprocessed nodes:  I = NEXT(I0) */
07935 /* KT =       Index of a triangulation node */
07936 /* KU =       Index of an unprocessed node and DO-loop index */
07937 /* LP =       LIST index (pointer) of a neighbor of KT */
07938 /* LPL =      Pointer to the last neighbor of KT */
07939 /* NEXTI =    NEXT(I) */
07940 /* NKU =      NEAR(KU) */
07941 
07942     /* Parameter adjustments */
07943     --dist;
07944     --next;
07945     --near__;
07946     --indx;
07947     --lend;
07948     --z__;
07949     --y;
07950     --x;
07951     --list;
07952     --lptr;
07953     --lcnt;
07954 
07955     /* Function Body */
07956     if (*n0 < 3) {
07957         *n = 0;
07958         *ier = -1;
07959         return 0;
07960     }
07961 
07962 /* Store the first triangle in the linked list. */
07963 
07964     if (! left_(&x[1], &y[1], &z__[1], &x[2], &y[2], &z__[2], &x[3], &y[3], &
07965             z__[3])) {
07966 
07967 /*   The first triangle is (3,2,1) = (2,1,3) = (1,3,2). */
07968 
07969         list[1] = 3;
07970         lptr[1] = 2;
07971         list[2] = -2;
07972         lptr[2] = 1;
07973         lend[1] = 2;
07974 
07975         list[3] = 1;
07976         lptr[3] = 4;
07977         list[4] = -3;
07978         lptr[4] = 3;
07979         lend[2] = 4;
07980 
07981         list[5] = 2;
07982         lptr[5] = 6;
07983         list[6] = -1;
07984         lptr[6] = 5;
07985         lend[3] = 6;
07986 
07987     } else if (! left_(&x[2], &y[2], &z__[2], &x[1], &y[1], &z__[1], &x[3], &
07988             y[3], &z__[3])) {
07989 
07990 /*   The first triangle is (1,2,3):  3 Strictly Left 1->2, */
07991 /*     i.e., node 3 lies in the left hemisphere defined by */
07992 /*     arc 1->2. */
07993 
07994         list[1] = 2;
07995         lptr[1] = 2;
07996         list[2] = -3;
07997         lptr[2] = 1;
07998         lend[1] = 2;
07999 
08000         list[3] = 3;
08001         lptr[3] = 4;
08002         list[4] = -1;
08003         lptr[4] = 3;
08004         lend[2] = 4;
08005 
08006         list[5] = 1;
08007         lptr[5] = 6;
08008         list[6] = -2;
08009         lptr[6] = 5;
08010         lend[3] = 6;
08011 
08012 
08013     } else {
08014 
08015 /*   The first three nodes are collinear. */
08016 
08017         *n = 0;
08018         *ier = -2;
08019         return 0;
08020     }
08021 
08022     //printf("pass check colinear\n");
08023 
08024 /* Initialize LNEW, INDX, and LCNT, and test for N = 3. */
08025 
08026     *lnew = 7;
08027     indx[1] = 1;
08028     indx[2] = 2;
08029     indx[3] = 3;
08030     lcnt[1] = 1;
08031     lcnt[2] = 1;
08032     lcnt[3] = 1;
08033     if (*n0 == 3) {
08034         *n = 3;
08035         *ier = 0;
08036         return 0;
08037     }
08038 
08039 /* A nearest-node data structure (NEAR, NEXT, and DIST) is */
08040 /*   used to obtain an expected-time (N*log(N)) incremental */
08041 /*   algorithm by enabling constant search time for locating */
08042 /*   each new node in the triangulation. */
08043 
08044 /* For each unprocessed node KU, NEAR(KU) is the index of the */
08045 /*   triangulation node closest to KU (used as the starting */
08046 /*   point for the search in Subroutine TRFIND) and DIST(KU) */
08047 /*   is an increasing function of the arc length (angular */
08048 /*   distance) between nodes KU and NEAR(KU):  -Cos(a) for */
08049 /*   arc length a. */
08050 
08051 /* Since it is necessary to efficiently find the subset of */
08052 /*   unprocessed nodes associated with each triangulation */
08053 /*   node J (those that have J as their NEAR entries), the */
08054 /*   subsets are stored in NEAR and NEXT as follows:  for */
08055 /*   each node J in the triangulation, I = NEAR(J) is the */
08056 /*   first unprocessed node in J's set (with I = 0 if the */
08057 /*   set is empty), L = NEXT(I) (if I > 0) is the second, */
08058 /*   NEXT(L) (if L > 0) is the third, etc.  The nodes in each */
08059 /*   set are initially ordered by increasing indexes (which */
08060 /*   maximizes efficiency) but that ordering is not main- */
08061 /*   tained as the data structure is updated. */
08062 
08063 /* Initialize the data structure for the single triangle. */
08064 
08065     near__[1] = 0;
08066     near__[2] = 0;
08067     near__[3] = 0;
08068     for (ku = *n0; ku >= 4; --ku) {
08069         d1 = -(x[ku] * x[1] + y[ku] * y[1] + z__[ku] * z__[1]);
08070         d2 = -(x[ku] * x[2] + y[ku] * y[2] + z__[ku] * z__[2]);
08071         d3 = -(x[ku] * x[3] + y[ku] * y[3] + z__[ku] * z__[3]);
08072         if (d1 <= d2 && d1 <= d3) {
08073             near__[ku] = 1;
08074             dist[ku] = d1;
08075             next[ku] = near__[1];
08076             near__[1] = ku;
08077         } else if (d2 <= d1 && d2 <= d3) {
08078             near__[ku] = 2;
08079             dist[ku] = d2;
08080             next[ku] = near__[2];
08081             near__[2] = ku;
08082         } else {
08083             near__[ku] = 3;
08084             dist[ku] = d3;
08085             next[ku] = near__[3];
08086             near__[3] = ku;
08087         }
08088 /* L1: */
08089     }
08090 
08091 /* Loop on unprocessed nodes KU.  KT is the number of nodes */
08092 /*   in the triangulation, and NKU = NEAR(KU). */
08093 
08094     kt = 3;
08095     i__1 = *n0;
08096     for (ku = 4; ku <= i__1; ++ku) {
08097         nku = near__[ku];
08098 
08099 /* Remove KU from the set of unprocessed nodes associated */
08100 /*   with NEAR(KU). */
08101         i__ = nku;
08102         if (near__[i__] == ku) {
08103             near__[i__] = next[ku];
08104         } else {
08105             i__ = near__[i__];
08106 L2:
08107             i0 = i__;
08108             i__ = next[i0];
08109             if (i__ != ku) {
08110                 goto L2;
08111             }
08112             next[i0] = next[ku];
08113         }
08114         near__[ku] = 0;
08115 
08116 /* Bypass duplicate nodes. */
08117 
08118         if (dist[ku] <= *tol - 1.) {
08119             indx[ku] = -nku;
08120             ++lcnt[nku];
08121             goto L6;
08122         }
08123 
08124 
08125 /* Add a new triangulation node KT with LCNT(KT) = 1. */
08126         ++kt;
08127         x[kt] = x[ku];
08128         y[kt] = y[ku];
08129         z__[kt] = z__[ku];
08130         indx[ku] = kt;
08131         lcnt[kt] = 1;
08132         addnod_(&nku, &kt, &x[1], &y[1], &z__[1], &list[1], &lptr[1], &lend[1]
08133                 , lnew, ier);
08134         if (*ier != 0) {
08135             *n = 0;
08136             *ier = -3;
08137             return 0;
08138         }
08139 
08140 /* Loop on neighbors J of node KT. */
08141 
08142         lpl = lend[kt];
08143         lp = lpl;
08144 L3:
08145         lp = lptr[lp];
08146         j = (i__2 = list[lp], abs(i__2));
08147 
08148 /* Loop on elements I in the sequence of unprocessed nodes */
08149 /*   associated with J:  KT is a candidate for replacing J */
08150 /*   as the nearest triangulation node to I.  The next value */
08151 /*   of I in the sequence, NEXT(I), must be saved before I */
08152 /*   is moved because it is altered by adding I to KT's set. */
08153 
08154         i__ = near__[j];
08155 L4:
08156         if (i__ == 0) {
08157             goto L5;
08158         }
08159         nexti = next[i__];
08160 
08161 /* Test for the distance from I to KT less than the distance */
08162 /*   from I to J. */
08163 
08164         d__ = -(x[i__] * x[kt] + y[i__] * y[kt] + z__[i__] * z__[kt]);
08165         if (d__ < dist[i__]) {
08166 
08167 /* Replace J by KT as the nearest triangulation node to I: */
08168 /*   update NEAR(I) and DIST(I), and remove I from J's set */
08169 /*   of unprocessed nodes and add it to KT's set. */
08170 
08171             near__[i__] = kt;
08172             dist[i__] = d__;
08173             if (i__ == near__[j]) {
08174                 near__[j] = nexti;
08175             } else {
08176                 next[i0] = nexti;
08177             }
08178             next[i__] = near__[kt];
08179             near__[kt] = i__;
08180         } else {
08181             i0 = i__;
08182         }
08183 
08184 /* Bottom of loop on I. */
08185 
08186         i__ = nexti;
08187         goto L4;
08188 
08189 /* Bottom of loop on neighbors J. */
08190 
08191 L5:
08192         if (lp != lpl) {
08193             goto L3;
08194         }
08195 L6:
08196         ;
08197     }
08198     *n = kt;
08199     *ier = 0;
08200     return 0;
08201 } /* trmsh3_ */

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

Definition at line 18656 of file util_sparx.cpp.

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

18656                                                                                                              {
18657 
18658         EMData *rot;
18659 
18660         const int nmax=3, mmax=3;
18661         char task[60], csave[60];
18662         long int lsave[4];
18663         long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
18664         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];
18665         long int SIXTY=60;
18666 
18667         //     We wish to have no output.
18668         iprint = -1;
18669 
18670         //c     We specify the tolerances in the stopping criteria.
18671         factr=1.0e1;
18672         pgtol=1.0e-5;
18673 
18674         //     We specify the dimension n of the sample problem and the number
18675         //        m of limited memory corrections stored.  (n and m should not
18676         //        exceed the limits nmax and mmax respectively.)
18677         n=3;
18678         m=3;
18679 
18680         //     We now provide nbd which defines the bounds on the variables:
18681         //                    l   specifies the lower bounds,
18682         //                    u   specifies the upper bounds.
18683         //                    x   specifies the initial guess
18684         x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0;
18685         x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5;
18686         x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5;
18687 
18688 
18689         //     We start the iteration by initializing task.
18690         // (**MUST clear remaining chars in task with spaces (else crash)!**)
18691         strcpy(task,"START");
18692         for (int i=5;i<60;i++)  task[i]=' ';
18693 
18694         //     This is the call to the L-BFGS-B code.
18695         // (* call the L-BFGS-B routine with task='START' once before loop *)
18696         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18697         //int step = 1;
18698 
18699         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
18700         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
18701 
18702                 if (strncmp(task,"FG",2)==0) {
18703                 //   the minimization routine has returned to request the
18704                 //   function f and gradient g values at the current x
18705 
18706                 //        Compute function value f for the sample problem.
18707                 rot = new EMData();
18708                 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2], 1.0f);
18709                 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18710                 //f = -f;
18711                 delete rot;
18712 
18713                 //        Compute gradient g for the sample problem.
18714                 float dt = 1.0e-3f;
18715                 rot = new EMData();
18716                 rot = image->rot_scale_trans2D((float)x[0]+dt, (float)x[1], (float)x[2], 1.0f);
18717                 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18718                 //f1 = -f1;
18719                 g[0] = (f1-f)/dt;
18720                 delete rot;
18721 
18722                 dt = 1.0e-2f;
18723                 rot = new EMData();
18724                 rot = image->rot_scale_trans2D((float)x[0], (float)x[1]+dt, (float)x[2], 1.0f);
18725                 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18726                 //f2 = -f2;
18727                 g[1] = (f2-f)/dt;
18728                 delete rot;
18729 
18730                 rot = new EMData();
18731                 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2]+dt, 1.0f);
18732                 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18733                 //f3 = -f3;
18734                 g[2] = (f3-f)/dt;
18735                 delete rot;
18736                 }
18737 
18738                 //c          go back to the minimization routine.
18739                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18740                 //step++;
18741         }
18742 
18743         //printf("Total step is %d\n", step);
18744         vector<float> res;
18745         res.push_back(static_cast<float>(x[0]));
18746         res.push_back(static_cast<float>(x[1]));
18747         res.push_back(static_cast<float>(x[2]));
18748         //res.push_back(step);
18749         return res;
18750 }

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

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

18752                                                                                                                                      {
18753 
18754         EMData *rot;
18755 
18756         const int nmax=3, mmax=3;
18757         char task[60], csave[60];
18758         long int lsave[4];
18759         long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
18760         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];
18761         long int SIXTY=60;
18762 
18763         //     We wish to have no output.
18764         iprint = -1;
18765 
18766         //c     We specify the tolerances in the stopping criteria.
18767         factr=1.0e1;
18768         pgtol=1.0e-5;
18769 
18770         //     We specify the dimension n of the sample problem and the number
18771         //        m of limited memory corrections stored.  (n and m should not
18772         //        exceed the limits nmax and mmax respectively.)
18773         n=3;
18774         m=3;
18775 
18776         //     We now provide nbd which defines the bounds on the variables:
18777         //                    l   specifies the lower bounds,
18778         //                    u   specifies the upper bounds.
18779         //                    x   specifies the initial guess
18780         x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0;
18781         x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5;
18782         x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5;
18783 
18784 
18785         //     We start the iteration by initializing task.
18786         // (**MUST clear remaining chars in task with spaces (else crash)!**)
18787         strcpy(task,"START");
18788         for (int i=5;i<60;i++)  task[i]=' ';
18789 
18790         //     This is the call to the L-BFGS-B code.
18791         // (* call the L-BFGS-B routine with task='START' once before loop *)
18792         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18793         //int step = 1;
18794 
18795         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
18796         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
18797 
18798                 if (strncmp(task,"FG",2)==0) {
18799                 //   the minimization routine has returned to request the
18800                 //   function f and gradient g values at the current x
18801 
18802                 //        Compute function value f for the sample problem.
18803                 rot = new EMData();
18804                 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2], kb, 1.0f);
18805                 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18806                 //f = -f;
18807                 delete rot;
18808 
18809                 //        Compute gradient g for the sample problem.
18810                 float dt = 1.0e-3f;
18811                 rot = new EMData();
18812                 rot = image->rot_scale_conv7((float)((x[0]+dt)*pi/180), (float)x[1], (float)x[2], kb, 1.0f);
18813                 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18814                 //f1 = -f1;
18815                 g[0] = (f1-f)/dt;
18816                 delete rot;
18817 
18818                 rot = new EMData();
18819                 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1]+dt, (float)x[2], kb, 1.0);
18820                 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18821                 //f2 = -f2;
18822                 g[1] = (f2-f)/dt;
18823                 delete rot;
18824 
18825                 rot = new EMData();
18826                 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2]+dt, kb, 1.0f);
18827                 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18828                 //f3 = -f3;
18829                 g[2] = (f3-f)/dt;
18830                 delete rot;
18831                 }
18832 
18833                 //c          go back to the minimization routine.
18834                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18835                 //step++;
18836         }
18837 
18838         //printf("Total step is %d\n", step);
18839         vector<float> res;
18840         res.push_back(static_cast<float>(x[0]));
18841         res.push_back(static_cast<float>(x[1]));
18842         res.push_back(static_cast<float>(x[2]));
18843         //res.push_back(step);
18844         return res;
18845 }

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

Definition at line 19004 of file util_sparx.cpp.

References ccc_images(), and Steepda().

19004                                                                                                                 {
19005 
19006         double  x[4];
19007         int n;
19008         int l = 3;
19009         int m = 200;
19010         double e = 1e-9;
19011         double step = 0.01;
19012         float (*my_func)(EMData* , EMData* , EMData* , float , float , float) = ccc_images;
19013 
19014         x[1] = ang;
19015         x[2] = sxs;
19016         x[3] = sys;
19017 
19018         Steepda(x, step, e, l, m, &n, my_func, image, refim, mask);   // Call steepest descent optimization subroutine
19019         //printf("Took %d steps\n", n);
19020 
19021         vector<float> res;
19022         res.push_back(static_cast<float>(x[1]));
19023         res.push_back(static_cast<float>(x[2]));
19024         res.push_back(static_cast<float>(x[3]));
19025         res.push_back(static_cast<float>(n));
19026         return res;
19027 }

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

References ccc_images_G(), and Steepda_G().

19287                                                                                                                                         {
19288 
19289         double  x[4];
19290         int n;
19291         int l = 3;
19292         int m = 200;
19293         double e = 1e-9;
19294         double step = 0.001;
19295         float (*my_func)(EMData* , EMData* , EMData* , Util::KaiserBessel&, float , float , float) = ccc_images_G;
19296 
19297         x[1] = ang;
19298         x[2] = sxs;
19299         x[3] = sys;
19300 
19301         Steepda_G(x, step, e, l, m, &n, my_func, image, refim, mask, kb);   // Call steepest descent optimization subroutine
19302         //printf("Took %d steps\n", n);
19303 
19304         vector<float> res;
19305         res.push_back(static_cast<float>(x[1]));
19306         res.push_back(static_cast<float>(x[2]));
19307         res.push_back(static_cast<float>(x[3]));
19308         res.push_back(static_cast<float>(n));
19309         return res;
19310 }

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

References EMAN::EMData::cmp(), dt, EMAN::EMData::extract_plane(), proj, setulb_(), and SIXTY.

18847                                                                                                                                                             {
18848 
18849         EMData *proj, *proj2;
18850 
18851         const int nmax=5, mmax=5;
18852         char task[60], csave[60];
18853         long int lsave[4];
18854         long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
18855         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];
18856         long int SIXTY=60;
18857 
18858         //     We wish to have no output.
18859         iprint = -1;
18860 
18861         //c     We specify the tolerances in the stopping criteria.
18862         factr=1.0e1;
18863         pgtol=1.0e-5;
18864 
18865         //     We specify the dimension n of the sample problem and the number
18866         //        m of limited memory corrections stored.  (n and m should not
18867         //        exceed the limits nmax and mmax respectively.)
18868         n=5;
18869         m=5;
18870 
18871         //     We now provide nbd which defines the bounds on the variables:
18872         //                    l   specifies the lower bounds,
18873         //                    u   specifies the upper bounds.
18874         //                    x   specifies the initial guess
18875         x[0] = phi;     nbd[0] = 2;     l[0] = phi-2.0;         u[0] = phi+2.0;
18876         x[1] = theta;   nbd[1] = 2;     l[1] = theta-2.0;       u[1] = theta+2.0;
18877         x[2] = psi;     nbd[2] = 2;     l[2] = psi-2.0;         u[2] = psi+2.0;
18878         x[3] = sxs;     nbd[3] = 2;     l[3] = sxs-2.0;         u[3] = sxs+2.0;
18879         x[4] = sys;     nbd[4] = 2;     l[4] = sys-2.0;         u[4] = sys+2.0;
18880 
18881 
18882         //     We start the iteration by initializing task.
18883         // (**MUST clear remaining chars in task with spaces (else crash)!**)
18884         strcpy(task,"START");
18885         for (int i=5;i<60;i++)  task[i]=' ';
18886 
18887         //     This is the call to the L-BFGS-B code.
18888         // (* call the L-BFGS-B routine with task='START' once before loop *)
18889         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18890         int step = 1;
18891 
18892         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
18893         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
18894 
18895                 if (strncmp(task,"FG",2)==0) {
18896                 //   the minimization routine has returned to request the
18897                 //   function f and gradient g values at the current x
18898 
18899                 //        Compute function value f for the sample problem.
18900                 proj = new EMData();
18901                 proj2 = new EMData();
18902                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
18903                 proj->fft_shuffle();
18904                 proj->center_origin_fft();
18905                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
18906                 proj->do_ift_inplace();
18907                 int M = proj->get_ysize()/2;
18908                 proj2 = proj->window_center(M);
18909                 f = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18910                 //f = -f;
18911                 delete proj;
18912                 delete proj2;
18913 
18914                 //        Compute gradient g for the sample problem.
18915                 float dt = 1.0e-3f;
18916                 proj = new EMData();
18917                 proj2 = new EMData();
18918                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0]+dt, "theta", (float)x[1], "psi", (float)x[2])), kb);
18919                 proj->fft_shuffle();
18920                 proj->center_origin_fft();
18921                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
18922                 proj->do_ift_inplace();
18923                 proj2 = proj->window_center(M);
18924                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18925                 //ft = -ft;
18926                 delete proj;
18927                 delete proj2;
18928                 g[0] = (ft-f)/dt;
18929 
18930                 proj = new EMData();
18931                 proj2 = new EMData();
18932                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1]+dt, "psi", (float)x[2])), kb);
18933                 proj->fft_shuffle();
18934                 proj->center_origin_fft();
18935                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
18936                 proj->do_ift_inplace();
18937                 proj2 = proj->window_center(M);
18938                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18939                 //ft = -ft;
18940                 delete proj;
18941                 delete proj2;
18942                 g[1] = (ft-f)/dt;
18943 
18944                 proj = new EMData();
18945                 proj2 = new EMData();
18946                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2]+dt)), kb);
18947                 proj->fft_shuffle();
18948                 proj->center_origin_fft();
18949                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
18950                 proj->do_ift_inplace();
18951                 proj2 = proj->window_center(M);
18952                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18953                 //ft = -ft;
18954                 delete proj;
18955                 delete proj2;
18956                 g[2] = (ft-f)/dt;
18957 
18958                 proj = new EMData();
18959                 proj2 = new EMData();
18960                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
18961                 proj->fft_shuffle();
18962                 proj->center_origin_fft();
18963                 proj->process_inplace("filter.shift", Dict("x_shift", x[3]+dt, "y_shift", x[4], "z_shift", 0.0f));
18964                 proj->do_ift_inplace();
18965                 proj2 = proj->window_center(M);
18966                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18967                 //ft = -ft;
18968                 delete proj;
18969                 delete proj2;
18970                 g[3] = (ft-f)/dt;
18971 
18972                 proj = new EMData();
18973                 proj2 = new EMData();
18974                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
18975                 proj->fft_shuffle();
18976                 proj->center_origin_fft();
18977                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4]+dt, "z_shift", 0.0f));
18978                 proj->do_ift_inplace();
18979                 proj2 = proj->window_center(M);
18980                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18981                 //ft = -ft;
18982                 delete proj;
18983                 delete proj2;
18984                 g[4] = (ft-f)/dt;
18985                 }
18986 
18987                 //c          go back to the minimization routine.
18988                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18989                 step++;
18990         }
18991 
18992         //printf("Total step is %d\n", step);
18993         vector<float> res;
18994         res.push_back(static_cast<float>(x[0]));
18995         res.push_back(static_cast<float>(x[1]));
18996         res.push_back(static_cast<float>(x[2]));
18997         res.push_back(static_cast<float>(x[3]));
18998         res.push_back(static_cast<float>(x[4]));
18999         //res.push_back(step);
19000         return res;
19001 }

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 C, ENTERFUNC, EXITFUNC, pi, real2FH(), set_complex(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), set_ri(), EMAN::EMData::set_ri(), EMAN::EMData::set_shuffled(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::to_zero(), update(), EMAN::EMData::update(), x, and y.

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

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

04465                                                                                           {
04466         int nring = numr.size()/3;
04467         float *ave = avep->get_data();
04468         float *dat = datp->get_data();
04469         int i, j, numr3i, np;
04470         float  arg, cs, si;
04471         int maxrin = numr(3,nring);
04472         if(mirror == 1) { //for mirrored data has to be conjugated
04473                 for (i=1; i<=nring; i++) {
04474                         numr3i = numr(3,i);
04475                         np     = numr(2,i)-1;
04476                         ave[np]   += dat[np];
04477                         ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04478                         for (j=2; j<numr3i; j=j+2) {
04479                                 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04480                                 cs = cos(arg);
04481                                 si = sin(arg);
04482                                 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04483                                 ave[np + j]    += dat[np + j]*cs - dat[np + j +1]*si;
04484                                 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs;
04485                         }
04486                 }
04487         } else {
04488                 for (i=1; i<=nring; i++) {
04489                         numr3i = numr(3,i);
04490                         np     = numr(2,i)-1;
04491                         ave[np]   += dat[np];
04492                         ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04493                         for (j=2; j<numr3i; j=j+2) {
04494                                 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04495                                 cs = cos(arg);
04496                                 si = sin(arg);
04497                                 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04498                                 ave[np + j]    += dat[np + j]*cs - dat[np + j +1]*si;
04499                                 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs;
04500                         }
04501                 }
04502         }
04503         avep->update();
04504         EXITFUNC;
04505 }

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

Definition at line 1043 of file util.h.

Referenced by multi_align_error_func().

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

Definition at line 20008 of file util_sparx.cpp.

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

20008                                     {
20009         const float step=0.001f;
20010         int ny = d->get_ysize();
20011         //  input emdata should have size 2xN, where N is number of points
20012         //  output vector should be 2xN, first element is the number of elements
20013         //  associated with this point, second is 0 is the element is touching the border, 1 if it is interior
20014         vector<float> group(2*ny);
20015         for(int i=0; i<2*ny; i++) group[i] = 0.0f;
20016         int K = int(1.0f/step) +1;
20017         int hit = 0;
20018         for(int kx=0; kx<=K; kx++) {
20019                 float tx = kx*step;
20020                 for(int ky=0; ky<=K; ky++) {
20021                         float ty = ky*step;
20022                         float dm = 1.0e23f;
20023                         for(int i=0; i<ny; i++) {
20024                                 float qd = pow(tx-(*d)(0,i),2) + pow(ty-(*d)(1,i),2);
20025                                 if( qd < dm) {
20026                                         dm = qd;
20027                                         hit = i;
20028                                 }
20029                         }
20030                         data(0,hit) += 1.0f;
20031                         if(kx == 0 || ky == 0 || kx == K || ky == K)  data(1,hit) = 1.0f;
20032                 }
20033         }
20034         return  group;
20035 }

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

Definition at line 7482 of file util_sparx.cpp.

References ang_to_xyz(), areav_(), Assert, disorder2(), ENTERFUNC, EXITFUNC, flip23(), key, status, trmsh3_(), and y.

07483 {
07484 
07485         ENTERFUNC;
07486 
07487         int *list, *lptr, *lend, *iwk, *key,*lcnt,*indx,*good;
07488         int nt6, n, ier, nout, lnew, mdup, nd;
07489         int i,k,mt,status;
07490 
07491 
07492         double *ds, *x, *y, *z;
07493         double tol  = 1.0e-8;
07494         double dtol = 15;
07495         double a;
07496 
07497         /*if(last){
07498                 if(medium>nt)  n = nt+nt;
07499                 else           n = nt+nt-medium+1;
07500         }
07501         else{
07502                 n=nt;
07503         }*/
07504 
07505         n = nt + nt;
07506 
07507         nt6 = n*6;
07508 
07509         list = (int*)calloc(nt6,sizeof(int));
07510         lptr = (int*)calloc(nt6,sizeof(int));
07511         lend = (int*)calloc(n  ,sizeof(int));
07512         iwk  = (int*)calloc(n  ,sizeof(int));
07513         good = (int*)calloc(n  ,sizeof(int));
07514         key  = (int*)calloc(n  ,sizeof(int));
07515         indx = (int*)calloc(n  ,sizeof(int));
07516         lcnt = (int*)calloc(n  ,sizeof(int));
07517 
07518         ds      =       (double*) calloc(n,sizeof(double));
07519         x       =       (double*) calloc(n,sizeof(double));
07520         y       =       (double*) calloc(n,sizeof(double));
07521         z       =       (double*) calloc(n,sizeof(double));
07522 
07523         if (list == NULL ||
07524         lptr == NULL ||
07525         lend == NULL ||
07526         iwk  == NULL ||
07527         good == NULL ||
07528         key  == NULL ||
07529         indx == NULL ||
07530         lcnt == NULL ||
07531         x    == NULL ||
07532         y    == NULL ||
07533         z    == NULL ||
07534         ds   == NULL) {
07535                 printf("memory allocation failure!\n");
07536                 exit(1);
07537         }
07538 
07539         bool colinear=true;
07540         while(colinear)
07541         {
07542 
07543         L1:
07544             for(i = 0; i<nt; i++){
07545                 x[i] = theta[i];
07546                 y[i] = phi[i];
07547                 x[nt+i] = 180.0 - x[i];
07548                 y[nt+i] = 180.0 + y[i];
07549             }
07550 
07551             Util::disorder2(x, y, key, n);
07552 
07553             // check if the first three angles are not close, else shuffle
07554             double val;
07555             for(k=0; k<2; k++){
07556                 for(i=k+1; i<3; i++){
07557                     val = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]);
07558                     if( val  < dtol) {
07559                         goto L1;
07560                     }
07561                 }
07562             }
07563 
07564             Util::ang_to_xyz(x, y, z, n);
07565 
07566             //  Make sure that first three has no duplication
07567             bool dupnode=true;
07568             dupnode=true;
07569             while(dupnode)
07570             {
07571                 for(k=0; k<2; k++){
07572                     for(i=k+1; i<3; i++){
07573                         if(  x[i]*x[k]+y[i]*y[k]+z[i]*z[k] > 1.0-tol) {
07574                                 Util::flip23(x, y, z, key, k, n);
07575                                 continue;
07576                         }
07577                     }
07578                 }
07579                 dupnode = false;
07580             }
07581 
07582 
07583             ier = 0;
07584 
07585             status = Util::trmsh3_(&n,&tol,x,y,z,&nout,list,lptr,lend,&lnew, indx, lcnt, iwk, good, ds, &ier);
07586 
07587             if (status != 0) {
07588                 printf(" error in trmsh3 \n");
07589                 exit(1);
07590             }
07591 
07592             if (ier > 0) {
07593                 printf("*** Error in TRMESH:  duplicate nodes encountered ***\n");
07594                 exit(1);
07595             }
07596 
07597             mdup=n-nout;
07598             if (ier == -2) {
07599                 //printf("in TRMESH:the first three nodes are colinear*** disorder again\n");
07600             }
07601             else
07602             {
07603                 colinear=false;
07604             }
07605         }
07606 
07607 
07608         Assert( ier != -2 );
07609 //  Create a list of unique nodes GOOD, the numbers refer to locations on the full list
07610 //  INDX contains node numbers from the squeezed list
07611         nd=0;
07612         for (k=1; k<=n; k++){
07613                 if (indx[k-1]>0) {
07614                         nd++;
07615                         good[nd-1]=k;
07616                 }
07617         }
07618 
07619 //
07620 // *** Compute the Voronoi region areas.
07621 //
07622         for(i = 1; i<=nout; i++) {
07623                 k=good[i-1];
07624                 //  We only need n weights from hemisphere
07625                 if (key[k-1] <= nt) {
07626 //  CALCULATE THE AREA
07627                         a = Util::areav_(&i, &nout, x, y, z, list, lptr, lend, &ier);
07628                         if (ier != 0){
07629 //  We set the weight to -1, this will signal the error in the calling
07630 //   program, as the area will turn out incorrect
07631                                 printf("    *** error in areav:  ier = %d ***\n", ier);
07632                                 weight[key[k-1]-1] =-1.0;
07633                         } else {
07634 //  Assign the weight
07635                                 weight[key[k-1]-1]=a/lcnt[i-1];
07636                         }
07637                 }
07638         }
07639 
07640 
07641 // Fill out the duplicated weights
07642         for(i = 1; i<=n; i++){
07643                 mt =- indx[i-1];
07644                 if (mt>0){
07645                         k = good[mt-1];
07646 //  This is a duplicated entry, get the already calculated
07647 //   weight and assign it.
07648                 //  We only need n weights from hemisphere
07649                         if (key[i-1] <= nt && key[k-1] <= nt) { weight[key[i-1]-1] = weight[key[k-1]-1];}
07650                         }
07651         }
07652 
07653         free(list);
07654         free(lend);
07655         free(iwk);
07656         free(good);
07657         free(key);
07658         free(lptr);
07659         free(indx);
07660         free(lcnt);
07661         free(ds);
07662         free(x);
07663         free(y);
07664         free(z);
07665 
07666 
07667         EXITFUNC;
07668 }

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

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

Definition at line 7059 of file util_sparx.cpp.

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

07060 {
07061 
07062         ENTERFUNC;
07063 
07064         if ( th.size() != ph.size() ) {
07065                 LOGERR("images not same size");
07066                 throw ImageFormatException( "images not same size");
07067         }
07068 
07069         // rand_seed
07070         srand(10);
07071 
07072         int i,*key;
07073         int len = th.size();
07074         double *theta,*phi,*weight;
07075         theta   =       (double*) calloc(len,sizeof(double));
07076         phi     =       (double*) calloc(len,sizeof(double));
07077         weight  =       (double*) calloc(len,sizeof(double));
07078         key     =       (int*) calloc(len,sizeof(int));
07079         const float *thptr, *phptr;
07080 
07081         thptr = &th[0];
07082         phptr = &ph[0];
07083         for(i=1;i<=len;i++){
07084                 key(i) = i;
07085                 weight(i) = 0.0;
07086         }
07087 
07088         for(i = 0;i<len;i++){
07089                 theta[i] = thptr[i];
07090                 phi[i]   = phptr[i];
07091         }
07092 
07093         //  sort by theta
07094         Util::hsortd(theta, phi, key, len, 1);
07095 
07096         //Util::voronoidiag(theta,phi, weight, len);
07097         Util::voronoi(phi, theta, weight, len);
07098 
07099         //sort by key
07100         Util::hsortd(weight, weight, key, len, 2);
07101 
07102         free(theta);
07103         free(phi);
07104         free(key);
07105         vector<double> wt;
07106         double count = 0;
07107         for(i=1; i<= len; i++)
07108         {
07109                 wt.push_back(weight(i));
07110                 count += weight(i);
07111         }
07112 
07113         //if( abs(count-6.28) > 0.1 )
07114         //{
07115         //    printf("Warning: SUM OF VORONOI CELLS AREAS IS %lf, should 2*PI\n", count);
07116         //}
07117 
07118         free(weight);
07119 
07120         EXITFUNC;
07121         return wt;
07122 
07123 }

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

05218 {
05219         /* Exception Handle */
05220         if (!img) throw NullPointerException("NULL input image");
05221         /* ============================== */
05222 
05223         // Get the size of the input image
05224         int nx=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize();
05225         /* ============================== */
05226 
05227         /* Exception Handle */
05228         if(new_nx>nx || new_ny>ny || new_nz>nz)
05229                 throw ImageDimensionException("The size of the windowed image cannot exceed the input image size.");
05230         if((nx/2)-(new_nx/2)+x_offset<0 || (ny/2)-(new_ny/2)+y_offset<0 || (nz/2)-(new_nz/2)+z_offset<0)
05231                 throw ImageDimensionException("The offset inconsistent with the input image size.");
05232         if(x_offset>((nx-(nx/2))-(new_nx-(new_nx/2))) || y_offset>((ny-(ny/2))-(new_ny-(new_ny/2))) || z_offset>((nz-(nz/2))-(new_nz-(new_nz/2))))
05233                 throw ImageDimensionException("The offset inconsistent with the input image size.");
05234         /* ============================== */
05235 
05236         /*    Calculation of the start point */
05237         int  new_st_x = nx/2-new_nx/2 + x_offset,
05238              new_st_y = ny/2-new_ny/2 + y_offset,
05239              new_st_z = nz/2-new_nz/2 + z_offset;
05240         /* ============================== */
05241 
05242         /* Exception Handle */
05243         if (new_st_x<0 || new_st_y<0 || new_st_z<0)   //  WHAT HAPPENS WITH THE END POINT CHECK??  PAP
05244                 throw ImageDimensionException("The offset inconsistent with the input image size.");
05245         /* ============================== */
05246 
05247         EMData* wind = img->copy_empty_head();
05248         wind->set_size(new_nx, new_ny, new_nz);
05249         float *outp=wind->get_data();
05250         float *inp=img->get_data();
05251 
05252         for (int k=0; k<new_nz; k++)
05253                 for(int j=0; j<new_ny; j++)
05254                         for(int i=0; i<new_nx; i++)
05255                                 outp(i,j,k) = inp(i,j,k);
05256         wind->update();
05257         return wind;
05258 }

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

Definition at line 5705 of file util_sparx.cpp.

References EMAN::EMData::get_data(), max, min, PROJ, q, SS, EMAN::EMData::update(), W, and Y.

05706 {
05707         int NSAM,NROW,NNNN,NR2,L,JY,KX,NANG;
05708         float WW,OX,OY;
05709 
05710         NSAM = PROJ->get_xsize();
05711         NROW = PROJ->get_ysize();
05712         int ntotal = NSAM*NROW;
05713         float q = 2.0f;
05714         float qt = 8.0f/q;
05715         //  Fix for padding 2x
05716         int ipad = 1;
05717         NSAM *= ipad;
05718         NROW *= ipad;
05719         NNNN = NSAM+2-(NSAM%2);
05720         int NX2 = NSAM/2;
05721         NR2  = NROW/2;
05722 
05723         NANG = int(SS.size())/6;
05724 
05725         EMData* W = new EMData();
05726         int Wnx = NNNN/2;
05727         W->set_size(Wnx,NROW,1);
05728         W->to_zero();
05729         float *Wptr = W->get_data();
05730         float *PROJptr = PROJ->get_data();
05731         for (L=1; L<=NANG; L++) {
05732                 float  tmp1 = SS(3,K)*SS(4,L)*(SS(1,K)*SS(1,L) + SS(2,K)*SS(2,L)) - SS(3,L)*SS(4,K);
05733                 float  tmp2 = SS(4,L)*( SS(1,K)*SS(2,L) - SS(1,L)*SS(2,K) ); 
05734                 OX = SS(6,K)*tmp2 + SS(5,K)*tmp1;
05735                 OY = SS(5,K)*tmp2 - SS(6,K)*tmp1;
05736                 if(OX < 0.0f) {
05737                         OX = -OX;
05738                         OY = -OY;
05739                 }
05740 
05741                 if( fabs(OX) > 1.0e-6f || fabs(OY) > 1.0e6f ) {
05742                         for(int J=1;J<=NROW;J++) {
05743                                 JY = (J-1);
05744                                 if(JY > NR2) JY -= NROW;
05745 #ifdef _WIN32
05746                                 int xma = _cpp_min(int(0.5f+(q-JY*OY)/OX),NX2);
05747                                 int xmi = _cpp_max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0);
05748 #else
05749                                 int xma = std::min(int(0.5f+(q-JY*OY)/OX),NX2);
05750                                 int xmi = std::max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0);
05751 #endif  //_WIN32
05752                                 if( xmi <= xma) {
05753                                         for(int I=xmi;I<=xma;I++) {
05754                                                 float Y = fabs(OX*I + OY*JY);
05755                                                 W(I+1,J) += exp(-qt*Y*Y);
05756         //cout << " L   "<<L << " I   "<<I << " JY   "<<JY << " ARG   "<<qt*Y*Y <<endl;
05757                                         }
05758                                 }
05759                         }
05760                 } else {
05761                         for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++)  W(I,J) += 1.0f;
05762                 }
05763         }
05764         EMData* proj_in = PROJ;
05765 
05766         PROJ = PROJ->norm_pad( false, ipad);
05767         PROJ->do_fft_inplace();
05768         PROJ->update();
05769         //cout << " x   "<<PROJ->get_xsize() << " y   "<<PROJ->get_ysize() <<endl;
05770         PROJptr = PROJ->get_data();
05771 
05772         float WNRMinv,temp;
05773         float osnr = 1.0f/SNR;
05774         WNRMinv = 1.0f/W(1,1);
05775         for(int J=1;J<=NROW;J++)  {
05776                 JY = J-1;
05777                 if( JY > NR2)  JY -= NROW;
05778                 float sy = JY;
05779                 sy /= NROW;
05780                 sy *= sy;
05781                 for(int I=1;I<=NNNN;I+=2) {
05782                         KX           = (I+1)/2;
05783                         temp         = W(KX,J)*WNRMinv;
05784                         WW           = temp/(temp*temp + osnr);
05785                         // This is supposed to fix fall-off due to Gaussian function in the weighting function
05786                         float sx = KX-1;
05787                         sx /= NSAM;
05788                         WW *= exp(qt*(sy + sx*sx));
05789                         PROJ(I,J)   *= WW;
05790                         PROJ(I+1,J) *= WW;
05791                 }
05792         }
05793         delete W; W = 0;
05794         PROJ->do_ift_inplace();
05795         PROJ->depad();
05796 
05797         float* data_src = PROJ->get_data();
05798         float* data_dst = proj_in->get_data();
05799 
05800         for( int i=0; i < ntotal; ++i )  data_dst[i] = data_src[i];
05801 
05802         proj_in->update();
05803 
05804         delete PROJ;
05805 }

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

Definition at line 5899 of file util_sparx.cpp.

References AMAX1, AMIN1, CC, CP, EMAN::EMData::get_data(), PROJ, RI, sqrt(), SS, EMAN::EMData::update(), VP, VV, and W.

05900 {
05901         float rad2deg =(180.0f/3.1415926f);
05902         float deg2rad = (3.1415926f/180.0f);
05903 
05904         int NSAM,NROW,NNNN,NR2,NANG,L,JY;
05905 
05906         NSAM = PROJ->get_xsize();
05907         NROW = PROJ->get_ysize();
05908         NNNN = NSAM+2-(NSAM%2);
05909         NR2  = NROW/2;
05910         NANG = int(SS.size())/6;
05911 
05912         float RI[9];
05913         RI(1,1)=SS(1,NUMP)*SS(3,NUMP)*SS(5,NUMP)-SS(2,NUMP)*SS(6,NUMP);
05914         RI(2,1)=-SS(1,NUMP)*SS(3,NUMP)*SS(6,NUMP)-SS(2,NUMP)*SS(5,NUMP);
05915         RI(3,1)=SS(1,NUMP)*SS(4,NUMP);
05916         RI(1,2)=SS(2,NUMP)*SS(3,NUMP)*SS(5,NUMP)+SS(1,NUMP)*SS(6,NUMP);
05917         RI(2,2)=-SS(2,NUMP)*SS(3,NUMP)*SS(6,NUMP)+SS(1,NUMP)*SS(5,NUMP);
05918         RI(3,2)=SS(2,NUMP)*SS(4,NUMP);
05919         RI(1,3)=-SS(4,NUMP)*SS(5,NUMP);
05920         RI(2,3)=SS(4,NUMP)*SS(6,NUMP);
05921         RI(3,3)=SS(3,NUMP);
05922 
05923         float THICK=static_cast<float>( NSAM)/DIAMETER/2.0f ;
05924 
05925         EMData* W = new EMData();
05926         int Wnx = NNNN/2;
05927         W->set_size(NNNN/2,NROW,1);
05928         W->to_one();
05929         float *Wptr = W->get_data();
05930 
05931         float ALPHA,TMP,FV,RT,FM,CCN,CC[3],CP[2],VP[2],VV[3];
05932 
05933         for (L=1; L<=NANG; L++) {
05934                 if (L != NUMP) {
05935                         CC(1)=SS(2,L)*SS(4,L)*SS(3,NUMP)-SS(3,L)*SS(2,NUMP)*SS(4,NUMP);
05936                         CC(2)=SS(3,L)*SS(1,NUMP)*SS(4,NUMP)-SS(1,L)*SS(4,L)*SS(3,NUMP);
05937                         CC(3)=SS(1,L)*SS(4,L)*SS(2,NUMP)*SS(4,NUMP)-SS(2,L)*SS(4,L)*SS(1,NUMP)*SS(4,NUMP);
05938 
05939                         TMP = sqrt(CC(1)*CC(1) +  CC(2)*CC(2) + CC(3)*CC(3));
05940                         CCN=static_cast<float>( AMAX1( AMIN1(TMP,1.0) ,-1.0) );
05941                         ALPHA=rad2deg*float(asin(CCN));
05942                         if (ALPHA>180.0f) ALPHA=ALPHA-180.0f;
05943                         if (ALPHA>90.0f) ALPHA=180.0f-ALPHA;
05944                         if(ALPHA<1.0E-6) {
05945                                 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J)+=1.0;
05946                         } else {
05947                                 FM=THICK/(fabs(sin(ALPHA*deg2rad)));
05948                                 CC(1)   = CC(1)/CCN;CC(2)   = CC(2)/CCN;CC(3)   = CC(3)/CCN;
05949                                 VV(1)= SS(2,L)*SS(4,L)*CC(3)-SS(3,L)*CC(2);
05950                                 VV(2)= SS(3,L)*CC(1)-SS(1,L)*SS(4,L)*CC(3);
05951                                 VV(3)= SS(1,L)*SS(4,L)*CC(2)-SS(2,L)*SS(4,L)*CC(1);
05952                                 CP(1)   = 0.0;CP(2) = 0.0;
05953                                 VP(1)   = 0.0;VP(2) = 0.0;
05954 
05955                                 CP(1) = CP(1) + RI(1,1)*CC(1) + RI(1,2)*CC(2) + RI(1,3)*CC(3);
05956                                 CP(2) = CP(2) + RI(2,1)*CC(1) + RI(2,2)*CC(2) + RI(2,3)*CC(3);
05957                                 VP(1) = VP(1) + RI(1,1)*VV(1) + RI(1,2)*VV(2) + RI(1,3)*VV(3);
05958                                 VP(2) = VP(2) + RI(2,1)*VV(1) + RI(2,2)*VV(2) + RI(2,3)*VV(3);
05959 
05960                                 TMP = CP(1)*VP(2)-CP(2)*VP(1);
05961 
05962                                 //     PREVENT TMP TO BE TOO SMALL, SIGN IS IRRELEVANT
05963                                 TMP = AMAX1(1.0E-4f,fabs(TMP));
05964                                 float tmpinv = 1.0f/TMP;
05965                                 for(int J=1;J<=NROW;J++) {
05966                                         JY = (J-1);
05967                                         if (JY>NR2)  JY=JY-NROW;
05968                                         for(int I=1;I<=NNNN/2;I++) {
05969                                                 FV     = fabs((JY*CP(1)-(I-1)*CP(2))*tmpinv);
05970                                                 RT     = 1.0f-FV/FM;
05971                                                 W(I,J) += ((RT>0.0f)*RT);
05972                                         }
05973                                 }
05974                         }
05975                 }
05976         }
05977 
05978         EMData* proj_in = PROJ;
05979 
05980         PROJ = PROJ->norm_pad( false, 1);
05981         PROJ->do_fft_inplace();
05982         PROJ->update();
05983         float *PROJptr = PROJ->get_data();
05984 
05985         int KX;
05986         float WW;
05987         for(int J=1; J<=NROW; J++)
05988                 for(int I=1; I<=NNNN; I+=2) {
05989                         KX          =  (I+1)/2;
05990                         WW          =  1.0f/W(KX,J);
05991                         PROJ(I,J)   = PROJ(I,J)*WW;
05992                         PROJ(I+1,J) = PROJ(I+1,J)*WW;
05993                 }
05994         delete W; W = 0;
05995         PROJ->do_ift_inplace();
05996         PROJ->depad();
05997 
05998         float* data_src = PROJ->get_data();
05999         float* data_dst = proj_in->get_data();
06000 
06001         int ntotal = NSAM*NROW;
06002         for( int i=0; i < ntotal; ++i )  data_dst[i] = data_src[i];
06003 
06004         proj_in->update();
06005         delete PROJ;
06006 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 10 23:02:07 2011 for EMAN2 by  doxygen 1.4.7