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

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

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

#include <util.h>

List of all members.

Static Public Member Functions

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 bb_enumerate_ (int *Parts, int *classDims, int nParts, int nClasses, int T, int n_guesses, int *levels)
 K is the number of classes in each partition (should be the same for all partitions) the first element of each class is its original index in the partition, and second is dummy var.
static void initial_prune (vector< vector< int * > > &Parts, int *dimClasses, int nParts, int K, int T)
 initial_prune removes all classes C from Parts where there does not exist ANY feasible matching containing class C which has weight gt T.
static bool explore (vector< vector< int * > > &Parts, int *dimClasses, int nParts, int K, int T, int partref, int *curintx, int size_curintx, int *next, int size_next, int depth)
 Each class in Parts has its dummy variable set to 0 or 1.
static int * branch (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *Levels, int nLevels, int curlevel, int n_guesses)
static int findTopLargest (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *matchlist, int max_num_matches, int *costlist, int n_guesses)
 find max_num_matches feasible matches (if possible) which has weight gt T, and weight gteq weight of all other feasible matches.
static int generatesubmax (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int n_guesses)
 make an intelligent "guess" at the largest weight of all possible feasible matches.
static void search2 (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int newT, int *curmax)
 return the weight of the largest weighted feasible match, along with the match in the (preallocated) argument curmax.
static int * explore2 (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int newT, int *curintx, int size_curintx, int *next, int size_next, int depth)
static bool sanitycheck (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *output)
 First element of output is total cost of the matches in the output Second element of output is the total number of matches in output So output has 2+(*(output+1))nParts elements.
static vector< int > bb_enumerateMPI_ (int *argParts, int *dimClasses, int nParts, int K, int T, int nTop, int n_guesses, bool doMPI, int *Levels)
 K is the number of classes in each partition (should be the same for all partitions) the first element of each class is its original index in the partition, and second is dummy var MPI: if nTop <= 0, then initial prune is called, and the pruned partitions are returned in a 1D array.
static vector< int > branchMPIpy_ (int *argParts, int *dimClasses, int nParts, int K, int T, int *Levels, int nLevels, int n_guesses, int nFirst, int *firstmatches)
 an interface function between python code and branchMPI.
static int * branchMPI (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *Levels, int nLevels, int curlevel, int n_guesses, int nFirst, int *firstmatches)
 same as branch except the nFirst (=Levels[0]) possibilites for the first match are already chosen firstmatches stores the matches and corresponding cost, where each match is preceded by its cost.
static vector< double > cml_weights (const vector< float > &cml)
static vector< int > cml_line_insino (vector< float > Rot, int i_prj, int n_prj)
 2009-03-25 15:35:53 JB.
static vector< int > cml_line_insino_all (vector< float > Rot, vector< int > seq, int n_prj, int n_lines)
 2009-03-30 15:35:07 JB.
static vector< double > cml_init_rot (vector< float > Ori)
 2009-03-25 15:35:05 JB.
static vector< float > cml_update_rot (vector< float > Rot, int iprj, float nph, float th, float nps)
 2009-03-25 15:35:37 JB.
static vector< double > cml_line_in3d (vector< float > Ori, vector< int > seq, int nprj, int nlines)
 2009-03-26 10:46:14 JB.
static vector< double > cml_spin_psi (const vector< EMData * > &data, vector< int > com, vector< float > weights, int iprj, vector< int > iw, int n_psi, int d_psi, int n_prj)
 2009-03-26 11:37:53 JB.
static double cml_disc (const vector< EMData * > &data, vector< int > com, vector< int > seq, vector< float > weights, int n_lines)
 2009-03-30 15:44:05 JB.
static void set_line (EMData *img, int posline, EMData *line, int offset, int length)
 This function drop a line (line) to an 2D image (img).
static void cml_prepare_line (EMData *sino, EMData *line, int ilf, int ihf, int pos_line, int nblines)
 This function prepare the line from sinogram by cutting off some frequencies, and creating the mirror part (complexe conjugate of the first part).
static 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, int size_img, int hist_len, EMData *img, vector< float > ref_freq_hist, EMData *mask, float ref_h_diff, float ref_h_min)
static float tf (float dzz, float ak, float voltage=300.0f, float cs=2.0f, float wgh=0.1f, float b_factor=0.0f, float sign=-1.0f)
static 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_delta (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, float delta_start, float delta)
 formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
static vector< float > multiref_polar_ali_2d_nom (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny)
 formerly known as apnq DO NOT CONSIDER MIRROR Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
static vector< float > multiref_polar_ali_2d_local (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, string mode, vector< int >numr, float cnx, float cny)
 formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
static vector< float > multiref_polar_ali_helical (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float psi_max, string mode, vector< int >numr, float cnx, float cny)
 formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation Search for peaks only within +/-psi_max from 0 and 180 (helical)
static vector< float > multiref_polar_ali_2d_local_psi (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, float psi_max, string mode, vector< int >numr, float cnx, float cny)
 formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
static void multiref_peaks_ali2d (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, EMData *peaks, EMData *peakm)
 Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08.
static void multiref_peaks_compress_ali2d (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, EMData *peaks, EMData *peakm, EMData *peaks_compress, EMData *peakm_compress)
 Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08.
static vector< float > ali2d_ccf_list (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, double T)
 Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation.
static vector< float > twoD_fine_ali (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys)
static vector< float > twoD_fine_ali_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys)
static vector< float > twoD_to_3D_ali (EMData *volft, Util::KaiserBessel &kb, EMData *refim, EMData *mask, float phi, float theta, float psi, float sxs, float sxy)
static vector< float > twoD_fine_ali_SD (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys)
static float ccc_images (EMData *, EMData *, EMData *, float, float, float)
static vector< float > twoD_fine_ali_SD_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys)
static float ccc_images_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sx, float sy)
static 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 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 17493 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().

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

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

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

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

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

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

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

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

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

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

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 1700 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 18346 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.

18348                                                                            {
18349 
18350         int   maxrin = numr[numr.size()-1];
18351 
18352         int   ky = int(2*yrng/step+0.5)/2;
18353         int   kx = int(2*xrng/step+0.5)/2;
18354 
18355         float *p_ccf1ds = (float *)malloc(maxrin*sizeof(float));
18356         float *p_ccf1dm = (float *)malloc(maxrin*sizeof(float));
18357         int vol = maxrin*(2*kx+1)*(2*ky+1);
18358         vector<ccf_point> ccf(2*vol);
18359         ccf_point temp;
18360 
18361         int index = 0;
18362         for (int i = -ky; i <= ky; i++) {
18363                 float iy = i * step;
18364                 for (int j = -kx; j <= kx; j++) {
18365                         float ix = j*step;
18366                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18367                         Frngs(cimage, numr);
18368                         Crosrng_msg_vec(crefim, cimage, numr, p_ccf1ds, p_ccf1dm);
18369                         for (int k=0; k<maxrin; k++) {
18370                                 temp.value = p_ccf1ds[k];
18371                                 temp.i = k;
18372                                 temp.j = j;
18373                                 temp.k = i;
18374                                 temp.mirror = 0;
18375                                 ccf[index] = temp;
18376                                 index++;
18377                                 temp.value = p_ccf1dm[k];
18378                                 temp.mirror = 1;
18379                                 ccf[index] = temp;
18380                                 index++;
18381                         }
18382                         delete cimage; cimage = 0;
18383                 }
18384         }
18385 
18386         delete p_ccf1ds;
18387         delete p_ccf1dm;
18388         std::sort(ccf.begin(), ccf.end(), ccf_value());
18389 
18390         double qt = (double)ccf[0].value;
18391         vector <double> p(2*vol), cp(2*vol);
18392 
18393         double sump = 0.0;
18394         for (int i=0; i<2*vol; i++) {
18395                 p[i] = pow(double(ccf[i].value)/qt, 1.0/T);
18396                 sump += p[i];
18397         }
18398         for (int i=0; i<2*vol; i++) {
18399                 p[i] /= sump;
18400         }
18401         for (int i=1; i<2*vol; i++) {
18402                 p[i] += p[i-1];
18403         }
18404         p[2*vol-1] = 2.0;
18405 
18406         float t = get_frand(0.0f, 1.0f);
18407         int select = 0;
18408         while (p[select] < t)   select += 1;
18409 
18410         vector<float> a(6);
18411         a[0] = ccf[select].value;
18412         a[1] = (float)ccf[select].i;
18413         a[2] = (float)ccf[select].j;
18414         a[3] = (float)ccf[select].k;
18415         a[4] = (float)ccf[select].mirror;
18416         a[5] = (float)select;
18417         return a;
18418 }

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

Definition at line 2360 of file util_sparx.cpp.

References circ, numr, quadri(), and y.

02361                                                                     {
02362         double dpi, dfi;
02363         int    it, jt, inr, l, nsim, kcirc, lt;
02364         float   xold, yold, fi, x, y;
02365 
02366         //     cns2 and cnr2 are predefined centers
02367         //     no need to set to zero, all elements are defined
02368 
02369         dpi = 2*atan(1.0);
02370         for (it=1; it<=nring; it++) {
02371                 // radius of the ring
02372                 inr = numr(1,it);
02373 
02374                 l = numr(3,it);
02375                 if ( mode == 'h' || mode == 'H' ) lt = l / 2;
02376                 else                              lt = l / 4;
02377 
02378                 nsim  = lt - 1;
02379                 dfi   = dpi / (nsim+1);
02380                 kcirc = numr(2,it);
02381 
02382 
02383                 xold  = 0.0f+cns2;
02384                 yold  = inr+cnr2;
02385 
02386                 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim);
02387 
02388                 xold  = inr+cns2;
02389                 yold  = 0.0f+cnr2;
02390                 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02391 
02392                 if ( mode == 'f' || mode == 'F' ) {
02393                         xold = 0.0f+cns2;
02394                         yold = -inr+cnr2;
02395                         circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02396 
02397                         xold = -inr+cns2;
02398                         yold = 0.0f+cnr2;
02399                         circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02400                 }
02401 
02402                 for (jt=1; jt<=nsim; jt++) {
02403                         fi   = static_cast<float>(dfi * jt);
02404                         x    = sin(fi) * inr;
02405                         y    = cos(fi) * inr;
02406 
02407                         xold = x+cns2;
02408                         yold = y+cnr2;
02409                         circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02410 
02411                         xold = y+cns2;
02412                         yold = -x+cnr2;
02413                         circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02414 
02415                         if ( mode == 'f' || mode == 'F' ) {
02416                                 xold = -x+cns2;
02417                                 yold = -y+cnr2;
02418                                 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02419 
02420                                 xold = -y+cns2;
02421                                 yold = x+cnr2;
02422                                 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02423                         }
02424                 } // end for jt
02425         } //end for it
02426 }

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

Definition at line 17740 of file util_sparx.cpp.

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

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

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

Definition at line 7686 of file util_sparx.cpp.

References dgr_to_rad, ENTERFUNC, and EXITFUNC.

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

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 1870 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 1838 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 1855 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 2093 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 8751 of file util_sparx.cpp.

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

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

References t.

Referenced by image_mutation().

19682                                                                                                                             {
19683 
19684         if (is_mirror != 0) {
19685                 for (int i=0; i<len_list; i++) {
19686                         int r = rand()%10000;
19687                         float f = r/10000.0f;
19688                         if (f < mutation_rate) list[i] = 1-list[i];
19689                 }
19690         } else {
19691                 map<int, vector<int> >  graycode;
19692                 map<vector<int>, int> rev_graycode;
19693                 vector <int> gray;
19694 
19695                 int K=1;
19696                 for (int i=0; i<L; i++) K*=2;
19697 
19698                 for (int k=0; k<K; k++) {
19699                         int shift = 0;
19700                         vector <int> gray;
19701                         for (int i=L-1; i>-1; i--) {
19702                                 int t = ((k>>i)%2-shift)%2;
19703                                 gray.push_back(t);
19704                                 shift += t-2;
19705                         }
19706                         graycode[k] = gray;
19707                         rev_graycode[gray] = k;
19708                 }
19709 
19710                 float gap = (K-1)/(max_val-min_val);
19711                 for (int i=0; i<len_list; i++) {
19712                         float val = list[i];
19713                         if (val < min_val) { val = min_val; }
19714                         else if  (val > max_val) { val = max_val; }
19715                         int k = int((val-min_val)*gap+0.5);
19716                         vector<int> gray = graycode[k];
19717                         bool changed = false;
19718                         for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) {
19719                                 int r = rand()%10000;
19720                                 float f = r/10000.0f;
19721                                 if (f < mutation_rate) {
19722                                         *p = 1-*p;
19723                                         changed = true;
19724                                 }
19725                         }
19726                         if (changed) {
19727                                 k = rev_graycode[gray];
19728                                 list[i] = k/gap+min_val;
19729                         }
19730                 }
19731         }
19732 
19733 }

void Util::bb_enumerate_ int *  Parts,
int *  classDims,
int  nParts,
int  nClasses,
int  T,
int  n_guesses,
int *  levels
[static]
 

K is the number of classes in each partition (should be the same for all partitions) the first element of each class is its original index in the partition, and second is dummy var.

Turn the one dimensional Parts into vectors for easier manipulation While we're at it, construct Indices, an nParts*K int array storing the index (into argparts) of the first element of the i-th class of the j-th partition So Indices[j*K + i] is the offset from argparts of the first element of the first element of the i-th class of the j-th partition

will delete this soon.... use bb_enumerateMPI instead

Definition at line 19789 of file util_sparx.cpp.

References branch(), and initial_prune().

19789                                                                                                             {
19790 
19791         int* Indices = new int[nParts*K];
19792         // Make a vector of nParts vectors of K int* each
19793         vector <vector <int*> > Parts(nParts,vector<int*>(K));
19794         int ind_c = 0;
19795 
19796         for (int i=0; i < nParts; i++){
19797                 for(int j = 0; j < K; j++){
19798                         Parts[i][j]=argParts + ind_c;
19799                         Indices[i*K + j] = ind_c;
19800                         ind_c = ind_c + *(dimClasses+i*K + j);
19801 
19802                 }
19803         }
19804 
19805         // make a copy of vector Parts for debugging purposes.
19806         // comment out if not debugging
19807         vector <vector <int*> > oldParts = Parts;
19808 
19809         // in the following we call initial_prune with Parts which is a vector. This is not the most
19810         // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and
19811         // the running time for 7 partitions with 288 classes per partition is on the order of a couple of minutes at most, i'll just leave it for now.....
19812         Util::initial_prune(Parts, dimClasses, nParts, K,T);
19813         //**********************************************************************************************************************************************
19814 
19815         // figure out the partition with the smallest number of classes. that will be the MAXIMUM number of matches we can find
19816         unsigned int numLevels = Parts[0].size();// initialize to number of classes in the first partition
19817         for (int i=1; i < nParts; i++){
19818                 if (Parts[i].size() < numLevels) numLevels = Parts[i].size();
19819         }
19820 
19821         // To maintain feasibility there can be at most
19822         // numLevel matches in the optimal solution.
19823 
19824         // int* Levels = new int[numLevels]; // Levels[i] corresponds to the number of possibilities we consider for the i-th match, and this
19825                                           // determines how many branches occur at that level.
19826         // numLevels is at most K. Since Levels is pre-allocated in python code with K elements, it should be fine.
19827         //for(int i =0; i < numLevels; i++)
19828         //      Levels[i] = 1;
19829         // modify argParts so the dummy variable of each class is set to 1 if the class is not removed by initial_prune, and -1 otherwise.
19830         // since the branch function is extremely computationally intensive, we have to pass it argParts (the 1-dimensional array) instead
19831         // of the vector Parts (which doesn't allow for direct access).
19832 
19833         // Indices[i*K + j] is the number of offsets from the beginning of argParts of the first element of the j-th class of hte i-th partition
19834 
19835         for(int i = 0; i < nParts; i++){
19836                 for(int j=0; j < K; j++){
19837                         *(argParts + Indices[i*K + j]+1) = -1;
19838                 }
19839         }
19840 
19841         int num_classes;
19842         int old_index;
19843         for(int i=0; i<nParts; i++){
19844                 num_classes = Parts[i].size();// number of classes in partition i after pruning
19845                 //cout<<"num_classes: "<< num_classes<<"\n";
19846                 for (int j=0; j < num_classes; j++){
19847                         old_index = *(Parts[i][j]);
19848                         //cout << "old_index: " << old_index<<"\n";
19849                         *(argParts + Indices[i*K + old_index]+1) = 1;
19850                 }
19851         }
19852 
19853         // 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
19854         // and the rest is the list of matches
19855         // in one dimensional form.
19856         cout <<"begin partition matching\n";
19857         int* output = Util::branch(argParts, Indices,dimClasses, nParts, K, T,Levels, numLevels,0,n_guesses);
19858         cout <<"done with partition matching \n";
19859         cout<<"total cost: "<<*output<<"\n";
19860         cout<<"number of matches: "<<*(output+1)<<"\n";
19861         // 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
19862         //bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output);
19863 }

vector< int > Util::bb_enumerateMPI_ int *  argParts,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int  nTop,
int  n_guesses,
bool  doMPI,
int *  Levels
[static]
 

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

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

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

Definition at line 20425 of file util_sparx.cpp.

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

20425                                                                                                                                              {
20426 
20427         // 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
20428         // 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
20429         // Make a vector of nParts vectors of K int* each
20430          int* Indices = new int[nParts*K];
20431          int ind_c = 0;
20432          for (int i=0; i < nParts; i++){
20433                  for(int j = 0; j < K; j++){
20434                          Indices[i*K + j] = ind_c;
20435                          ind_c = ind_c + *(dimClasses+i*K + j);
20436 
20437                  }
20438          }
20439 
20440         // return top weighted matches for mpi version
20441         if (nTop > 0 && doMPI > 0){
20442                  // find the nTop largest matches (not required to be mutually feasible)
20443                 int* matchlist = new int[nTop*nParts];
20444                 int* costlist=new int[nTop];
20445                 for (int i=0; i< nTop; i++) {*(costlist+i) = 0;}
20446                 int matchesFound = Util::findTopLargest(argParts,Indices, dimClasses, nParts, K,  T, matchlist, nTop,costlist,n_guesses);
20447                 vector<int> ret(nTop*(nParts+1) + 1);
20448                 ret[0] = matchesFound;
20449                 int m = nParts + 1;
20450                 // For each match in matchlist and its corresponding cost in costlist, put them in ret
20451                 for(int i=0; i < nTop; i++){
20452                         ret[1+i*m] = *(costlist+i);
20453                         for (int j=0; j < nParts; j++){
20454                                 ret[1+i*m + 1 + j] = matchlist[i*nParts + j];
20455                         }
20456                 }
20457 
20458                 return ret;
20459 
20460         }
20461 
20462         // do initial pruning on argParts and return the pruned partitions
20463 
20464         // Make a vector of nParts vectors of K int* each
20465         vector <vector <int*> > Parts(nParts,vector<int*>(K));
20466         ind_c = 0;
20467         int argParts_size=0;
20468         for (int i=0; i < nParts; i++){
20469                 for(int j = 0; j < K; j++){
20470                         Parts[i][j]=argParts + ind_c;
20471                         ind_c = ind_c + *(dimClasses+i*K + j);
20472                         argParts_size = argParts_size + *(dimClasses+i*K + j);
20473 
20474                 }
20475         }
20476 
20477         // in the following we call initial_prune with Parts which is a vector. This is not the most
20478         // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and
20479         // 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.....
20480 
20481         Util::initial_prune(Parts, dimClasses, nParts, K,T);
20482         for(int i = 0; i < nParts; i++){
20483                 for(int j=0; j < K; j++){
20484                         *(argParts + Indices[i*K + j]+1) = -1;
20485                 }
20486         }
20487 
20488         int num_classes;
20489         int old_index;
20490         for(int i=0; i<nParts; i++){
20491                 num_classes = Parts[i].size();// number of classes in partition i after pruning
20492                 for (int j=0; j < num_classes; j++){
20493                         old_index = *(Parts[i][j]);
20494                         //cout << "old_index: " << old_index<<"\n";
20495                         *(argParts + Indices[i*K + old_index]+1) = 1;
20496                 }
20497         }
20498 
20499 
20500         if (doMPI > 0){
20501                 // turn argParts into vector ret and return ret
20502                 vector<int> ret(argParts_size);
20503                 for(int i=0; i < argParts_size; i++)
20504                         ret[i]= (*(argParts+i));
20505 
20506                 return ret;
20507         }
20508 
20509         // if we're not doing mpi then keep going and call branchMPI and return the output
20510         //cout <<"begin partition matching\n";
20511         int* dummy(0);
20512         int* output = Util::branchMPI(argParts, Indices,dimClasses, nParts, K, T,Levels, K,0,n_guesses,-1, dummy);
20513         //cout <<"done with partition matching \n";
20514         //cout<<"total cost: "<<*output<<"\n";
20515         //cout<<"number of matches: "<<*(output+1)<<"\n";
20516         // 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
20517         bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output);
20518 
20519         // something is wrong with output of branchMPI!
20520         if (correct < 1){
20521                 cout << "something is wrong with output of branchMPI!\n";
20522                 vector<int> ret(1);
20523                 ret[0]=-1;
20524                 return ret;
20525         }
20526 
20527         // output is not nonsense, so now put it into a single dimension vector and return
20528         // 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
20529         // and the rest is the list of matches. output is one dimensional
20530 
20531         int output_size = 2+ *(output+1) * nParts;
20532         vector<int> ret(output_size);
20533         for (int i = 0; i < output_size; i++){
20534                 ret[i]=*(output+i);
20535         }
20536         return ret;
20537 
20538 }

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

Definition at line 2311 of file util_sparx.cpp.

References xim.

02312 {
02313 /*
02314 c  purpose: linear interpolation
02315   Optimized for speed, circular closer removed, checking of ranges removed
02316 */
02317     float bilinear;
02318     int   ixold, iyold;
02319 
02320 /*
02321         float xdif, ydif, xrem, yrem;
02322         ixold   = (int) floor(xold);
02323         iyold   = (int) floor(yold);
02324         ydif = yold - iyold;
02325         yrem = 1.0f - ydif;
02326 
02327         //  May want to insert if?
02328 //              IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND.
02329 //     &            (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN
02330 //c                INSIDE BOUNDARIES OF OUTPUT IMAGE
02331         xdif = xold - ixold;
02332         xrem = 1.0f- xdif;
02333 //                 RBUF(K) = YDIF*(BUF(NADDR+NSAM)*XREM
02334 //     &                    +BUF(NADDR+NSAM+1)*XDIF)
02335 //     &                    +YREM*(BUF(NADDR)*XREM + BUF(NADDR+1)*XDIF)
02336         bilinear = ydif*(xim(ixold,iyold+1)*xrem + xim(ixold+1,iyold+1)*xdif) +
02337                                         yrem*(xim(ixold,iyold)*xrem+xim(ixold+1,iyold)*xdif);
02338 
02339     return bilinear;
02340 }
02341 */
02342         float xdif, ydif;
02343 
02344         ixold   = (int) xold;
02345         iyold   = (int) yold;
02346         ydif = yold - iyold;
02347 
02348         //  May want to insert it?
02349 //              IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND.
02350 //     &            (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN
02351 //c                INSIDE BOUNDARIES OF OUTPUT IMAGE
02352         xdif = xold - ixold;
02353         bilinear = xim(ixold, iyold) + ydif* (xim(ixold, iyold+1) - xim(ixold, iyold)) +
02354                    xdif* (xim(ixold+1, iyold) - xim(ixold, iyold) +
02355                            ydif* (xim(ixold+1, iyold+1) - xim(ixold+1, iyold) - xim(ixold, iyold+1) + xim(ixold, iyold)) );
02356 
02357         return bilinear;
02358 }

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

Calculate bilinear interpolation.

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

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

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

Definition at line 5644 of file util_sparx.cpp.

References B, CUBE, DM, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::Transform::get_params(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), and t.

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

int * Util::branch int *  argParts,
int *  Indices,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int *  Levels,
int  nLevels,
int  curlevel,
int  n_guesses
[static]
 

Definition at line 19914 of file util_sparx.cpp.

References branch(), and findTopLargest().

19914                                                                                                                                               {
19915         // Base Case: we're at a leaf, no more feasible matches possible
19916 
19917         if (curlevel > nLevels-1){
19918                 int* res = new int[2];
19919                 *res = 0;
19920                 *(res+1)=0;
19921                 return res;
19922         }
19923 
19924         // We may still find more feasible matchings with cost gt T, so explore level curlevel
19925         int nBranches = *(Levels + curlevel);
19926 
19927         // call findTopLargest to get the nBranches feasible matchings with the largest weight (gt T) over all other feasible matches
19928         // matchlist is in one dimensional array form......
19929 
19930         int* matchlist = new int[nBranches*nParts];
19931         int* costlist = new int[nBranches];// cost of each of the nBranches matches. If cost[i] < T then that means findTopLargest found less than i+1 matches
19932                                            // with cost > T
19933 
19934         // initialize elements of costlist to 0
19935         for (int i=0; i < nBranches; i++) *(costlist+i)=0;
19936 
19937         // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart
19938         // each match contains nParts classes, with the i-th class belonging to the i-th partition.
19939 
19940         Util::findTopLargest(argParts,Indices, dimClasses, nParts, K,  T, matchlist, nBranches,costlist,n_guesses);
19941 
19942         // if there are no feasible matches with cost gt T, then return 0
19943         if (costlist[0]<= T){
19944                 int* res = new int[2];
19945                 *res = 0;
19946                 *(res+1)=0;
19947                 return res;
19948         }
19949 
19950         int* maxreturn = new int[2];//initialize to placeholder
19951         *maxreturn=0;
19952         *(maxreturn+1)=0;
19953 
19954         // some temporary variables
19955         int old_index;
19956         int totalcost;
19957         int nmatches;
19958         //int offset;
19959 
19960         for(int i=0; i < nBranches ; i++){
19961 
19962                 // consider the i-th match returned by findTopLargest
19963 
19964                 if (costlist[i] <= T) break;
19965 
19966                 // 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.
19967                 // After branch returns, compute overall cost, unmark  the classes just marked as 1 again in preparation for next loop.
19968 
19969                 for(int j=0; j < nParts; j++){
19970                         // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match.
19971                         old_index=matchlist[i*nParts + j];
19972                         *(argParts + Indices[j*K+old_index] + 1) = -2;
19973                 }
19974 
19975 
19976                 int* ret = Util::branch(argParts, Indices, dimClasses, nParts, K, T, Levels, nLevels, curlevel+1,n_guesses);
19977 
19978                 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret
19979                 totalcost = costlist[i] + *ret;
19980 
19981                 // *************************************************************************************
19982                 // for debugging purposes
19983 
19984                 // debug 1: for multi-branching in levels i less some pre-specified maxLevel. Assume maxLevel is pretty small else way too many print outs to be useful
19985                    bool debug1 = 0;
19986                    if (debug1){
19987                        int maxLevel = 2;
19988                         if (curlevel < maxLevel) cout<<"total cost level" << curlevel<<": "<<totalcost<<"\n";
19989                    }
19990 
19991                 // debug 2: for multi-branching in ALL (or many ...) levels. This is data specific so it's all hard coded
19992                    bool debug2 = 0;
19993                    if (debug2){
19994                         int skip1 = 5;
19995                         int max1=20;
19996                          if ((curlevel <= max1) && (curlevel%skip1 == 0)) cout << "total cost level "<< curlevel<<": "<<totalcost<<"\n";
19997 
19998                         int skip2 = 10;
19999                         int max2 = 70;
20000                         if ((curlevel > max1 )&&(curlevel <= max2) && (curlevel%skip2 == 0)) cout << "total cost level "<< curlevel<<": "<<totalcost<<"\n";
20001                    }
20002                 // *************************************************************************************
20003 
20004 
20005                 // if totalcost > maxcost, or some variatio thereof, then copy the stuff over to maxreturn.
20006                 // There are several possibilities here:
20007                 //    Option 1: Simply compare costs and take the largest one.
20008                 //    Option 2: At each level, if two costs are equal, then take the one which contains fewer matches, and thus
20009                 //              ensuring matches with larger weights. The motivation for this is largely the (possibly naive) assumption that
20010                 //              if we take the average of a larger number of images, then the averaged image will be "better".
20011                 //    Option 3: Do option 2 only on the highest level, i.e., curlevel=0
20012 
20013                  if (totalcost > *maxreturn) // option 1
20014                 // if ((totalcost > *maxreturn) || ( (curlevel==0) && (totalcost == *maxreturn) && (*(ret+1)+1 < *(maxreturn+1)) )) // option 3
20015 
20016                 //if ((totalcost > *maxreturn) || ( (totalcost == *maxreturn) && (*(ret+1)+1 < *(maxreturn+1)) )) // option 2
20017                 {
20018                         nmatches = 1 + *(ret+1);
20019                         delete[] maxreturn; // get rid of the old maxreturn
20020                         maxreturn = new int[2+nmatches*nParts];
20021                         *maxreturn = totalcost;
20022                         *(maxreturn + 1)= nmatches;
20023                         int nret = 2+(nmatches-1)*nParts;
20024                         for(int iret=2; iret <nret;iret++) *(maxreturn+iret)=*(ret+iret);
20025                         for(int imax=0; imax<nParts;imax++) *(maxreturn+nret+imax)=matchlist[i*nParts + imax];
20026                 }
20027 
20028 
20029                 delete[] ret;
20030 
20031                 // unmark the marked classes in preparation for the next iteration
20032 
20033                 for(int j=0; j < nParts; j++){
20034                         // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match.
20035                         old_index=matchlist[i*nParts + j];
20036                         *(argParts + Indices[j*K+old_index] + 1) = 1;
20037                 }
20038 
20039         }
20040 
20041         delete[] matchlist;
20042         delete[] costlist;
20043         return maxreturn;
20044 
20045 }

int * Util::branchMPI int *  argParts,
int *  Indices,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int *  Levels,
int  nLevels,
int  curlevel,
int  n_guesses,
int  nFirst,
int *  firstmatches
[static]
 

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

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

Definition at line 20594 of file util_sparx.cpp.

References branchMPI(), and findTopLargest().

20594                                                                                                                                                                                 {
20595 
20596         // Base Case: we're at a leaf, no more feasible matches possible
20597         if (curlevel > nLevels-1){
20598                 int* res = new int[2];
20599                 *res = 0;
20600                 *(res+1)=0;
20601                 return res;
20602         }
20603 
20604 
20605         // We may still find more feasible matchings with cost gt T, so explore level curlevel
20606         int nBranches = *(Levels + curlevel);
20607 
20608         // MPI: the first match is already chosen in MPI version, so we are going to branch only once at level 0
20609         if (curlevel==0 && nFirst > 0)
20610         {
20611                 nBranches = nFirst;
20612         }
20613 
20614         // call findTopLargest to get the nBranches feasible matchings with the largest weight (gt T) over all other feasible matches
20615 
20616         int* matchlist = new int[nBranches*nParts];
20617         int* costlist = new int[nBranches];// cost of each of the nBranches matches. If cost[i] < T then that means findTopLargest found less than i+1 matches
20618                                            // with cost > T
20619 
20620         for (int i=0; i < nBranches; i++)
20621                 *(costlist+i)=0;
20622 
20623         // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart
20624         // each match contains nParts classes, with the i-th class belonging to the i-th partition.
20625 
20626         // MPI: first match is already chosen, so copy the match in first match over to matchlist, compute weight of match, and set costlist to the weight
20627         if (curlevel == 0 && nFirst > 0){
20628                 for(int i = 0; i < nBranches; i++){
20629                         *(costlist+i) = *(firstmatches +i*(nParts+1));
20630                         for (int j=0; j< nParts; j++)
20631                                 *(matchlist + i*nParts +j) = *(firstmatches +i*(nParts+1) + 1 + j);
20632                 }
20633         }
20634         else
20635                 Util::findTopLargest(argParts,Indices, dimClasses, nParts, K,  T, matchlist, nBranches,costlist,n_guesses);
20636 
20637         // if there are no feasible matches with cost gt T, then return 0
20638         if (costlist[0]<= T){
20639                 int* res = new int[2];
20640                 *res = 0;
20641                 *(res+1)=0;
20642                 return res;
20643         }
20644 
20645         int* maxreturn = new int[2];//initialize to placeholder
20646         *maxreturn=0;
20647         *(maxreturn+1)=0;
20648 
20649         // some temporary variables
20650         int old_index;
20651         int totalcost;
20652         int nmatches;
20653         //int offset;
20654 
20655         for(int i=0; i < nBranches ; i++){
20656 
20657                 // consider the i-th match returned by findTopLargest
20658 
20659                 if (costlist[i] <= T) break;
20660 
20661                 // 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.
20662                 // After branch returns, compute overall cost, unmark  the classes just marked as 1 again in preparation for next loop.
20663 
20664                 for(int j=0; j < nParts; j++){
20665                         // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match.
20666                         old_index=matchlist[i*nParts + j];
20667                         *(argParts + Indices[j*K+old_index] + 1) = -2;
20668                 }
20669 
20670 
20671                 int* ret = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T, Levels, nLevels, curlevel+1,n_guesses, nFirst, firstmatches);
20672 
20673                 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret
20674                 totalcost = costlist[i] + *ret;
20675 
20676 
20677                  if (totalcost > *maxreturn) // option 1
20678                 {
20679                         nmatches = 1 + *(ret+1);
20680                         delete[] maxreturn; // get rid of the old maxreturn
20681                         maxreturn = new int[2+nmatches*nParts];
20682                         *maxreturn = totalcost;
20683                         *(maxreturn + 1)= nmatches;
20684                         int nret = 2+(nmatches-1)*nParts;
20685                         for(int iret=2; iret <nret;iret++) *(maxreturn+iret)=*(ret+iret);
20686                         for(int imax=0; imax<nParts;imax++) *(maxreturn+nret+imax)=matchlist[i*nParts + imax];
20687                 }
20688 
20689 
20690                 delete[] ret;
20691 
20692                 // unmark the marked classes in preparation for the next iteration
20693 
20694                 for(int j=0; j < nParts; j++){
20695                         // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match.
20696                         old_index=matchlist[i*nParts + j];
20697                         *(argParts + Indices[j*K+old_index] + 1) = 1;
20698                 }
20699 
20700         }
20701 
20702         delete[] matchlist;
20703         delete[] costlist;
20704 
20705         return maxreturn;
20706 
20707 }

vector< int > Util::branchMPIpy_ int *  argParts,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int *  Levels,
int  nLevels,
int  n_guesses,
int  nFirst,
int *  firstmatches
[static]
 

an interface function between python code and branchMPI.

Doesn't do much except compute Indices, call branchMPI, and check if the output make sense (i.e., feasible etc), and process the output to return to python as a vector. nFirst is the number of matches in firstmatches

Definition at line 20540 of file util_sparx.cpp.

References branchMPI(), and sanitycheck().

20540                                                                                                                                                               {
20541         //cout<<"branchMPIpy_ called\n";
20542         // if nLevels == K, then we  compute nLevels - which is the number of active classes of the partition with the smallest number of active classes
20543         // this is not really necessary but would save a call to findTopLargest in branchMPI
20544         int num_active;
20545         int* Indices = new int[nParts*K];
20546         // Make a vector of nParts vectors of K int* each
20547         int ind_c = 0;
20548         for (int i=0; i < nParts; i++){
20549                 num_active = 0;
20550                 for(int j = 0; j < K; j++){
20551                         Indices[i*K + j] = ind_c; // offset from argParts of the first element of the jth class of the i-th partition
20552                         if (*(argParts+ind_c + 1) == 1) num_active = num_active + 1;
20553                         ind_c = ind_c + *(dimClasses+i*K + j);
20554                 }
20555 
20556                 if (num_active < nLevels) {nLevels = num_active;}
20557         }
20558 
20559 
20560         //add in code for dynamically changing levels
20561 
20562         //cout<<"num levels "<<nLevels<<"\n";
20563         //cout<<"calling branchMPI\n";
20564 
20565         int* output = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T,  Levels,  nLevels, 0,n_guesses, nFirst,firstmatches);
20566 
20567         // call sanity check on outupt to make sure the returned matches are feasible with cost over the threshold T
20568         //cout<<"total cost: "<<*output<<"\n";
20569         //cout<<"number of matches: "<<*(output+1)<<"\n";
20570         // 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
20571         bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output);
20572 
20573         // something is wrong with output of branchMPI!
20574         if (correct < 1){
20575                 cout << "something is wrong with output of branchMPI!\n";
20576                 vector<int> ret(1);
20577                 ret[0]=-1;
20578                 return ret;
20579         }
20580 
20581         // output is not nonsense, so now put it into a single dimension vector and return
20582         // 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
20583         // and the rest is the list of matches. output is one dimensional
20584 
20585         int output_size = 2+ *(output+1) * nParts;
20586         vector<int> ret(output_size);
20587         for (int i = 0; i < output_size; i++){
20588                 ret[i]=*(output+i);
20589         }
20590         return ret;
20591 }

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 982 of file util.cpp.

References Assert, and LOGERR.

Referenced by EMAN::RTFExhaustiveAligner::align(), EMAN::RotatePrecenterAligner::align(), and EMAN::EMData::unwrap_largerR().

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

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

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

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

References lsfit().

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

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

Definition at line 5596 of file util_sparx.cpp.

References DGR_TO_RAD, DM, and SS.

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

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

Definition at line 18861 of file util_sparx.cpp.

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

Referenced by twoD_fine_ali_SD().

18861                                                                                                 {
18862 
18863         EMData *rot= new EMData();
18864         float ccc;
18865 
18866         rot = image->rot_scale_trans2D(ang, sx, sy, 1.0);
18867         ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18868         delete rot;
18869         return ccc;
18870 }

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

Definition at line 18898 of file util_sparx.cpp.

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

Referenced by twoD_fine_ali_SD_G().

18898                                                                                                                         {
18899 
18900         EMData *rot= new EMData();
18901         float ccc;
18902 
18903         rot = image->rot_scale_conv7(static_cast<float>(ang*pi/180.0), sx, sy, kb, 1.0f);
18904         ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18905         delete rot;
18906         return ccc;
18907 }

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

References abs, and in.

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

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

Definition at line 19495 of file util_sparx.cpp.

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

19495                                                {
19496         //  WORKS ONLY FOR NUMBER OF OBJECTS N=l^2   !!
19497         int nx = d->get_xsize();
19498         int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0);
19499         int K = N/2;
19500         vector<float> group(N);
19501         if(N*(N-1)/2 != nx) {
19502                 //print  "  incorrect dimension"
19503                 return group;}
19504         //bool active[N];       //this does not compile in VS2005. --Grant Tang
19505         bool * active = new bool[N];
19506         for(int i=0; i<N; i++) active[i] = true;
19507 
19508         float dm, qd;
19509         int   ppi = 0, ppj = 0;
19510         for(int k=0; k<K; k++) {
19511                 // find pairs of most similiar objects among active
19512                 //cout<<"  k  "<<k<<endl;
19513                 dm = 1.0e23f;
19514                 for(int i=1; i<N; i++) {
19515                         if(active[i]) {
19516                                 for(int j=0; j<i; j++) {
19517                                         if(active[j]) {
19518                                                 qd = (*d)(i*(i - 1)/2 + j);
19519                                                 if(qd < dm) {
19520                                                         dm = qd;
19521                                                         ppi = i;
19522                                                         ppj = j;
19523                                                 }
19524                                         }
19525                                 }
19526                         }
19527                 }
19528                 group[2*k] = float(ppi);
19529                 group[1+2*k] = float(ppj);
19530                 active[ppi] = false;
19531                 active[ppj] = false;
19532         }
19533 
19534         delete [] active;
19535         active = NULL;
19536         return  group;
19537 }

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

Definition at line 19287 of file util_sparx.cpp.

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

19287                                                                        {
19288         int nx = d->get_xsize();
19289         int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0);
19290         vector<float> out(N+K+2);
19291         if(N*(N-1)/2 != nx) {
19292                 //print  "  incorrect dimension"
19293                 return out;}
19294         //  assign random objects as centers
19295         for(int i=0; i<N; i++) assign(i) = float(i);
19296         // shuffle
19297         for(int i=0; i<N; i++) {
19298                 int j = Util::get_irand(0,N-1);
19299                 float temp = assign(i);
19300                 assign(i) = assign(j);
19301                 assign(j) = temp;
19302         }
19303         for(int k=0; k<K; k++) cent(k) = float(assign(k));
19304         //for(int k=0; k<K; k++) cout<<cent(k)<<"    ";cout<<endl;
19305         //
19306         for(int i=0; i<N; i++) assign(i) = 0.0f;
19307         float qm, dispold = 1.1e22f, disp = 1.0e22f, na=0.0f;
19308         bool change = true;
19309         int it = -1;
19310         int ct = -1;
19311         while(change && disp < dispold || ct > 0) {
19312 
19313                 change = false;
19314                 dispold = disp;
19315                 it++;
19316 
19317                 // dispersion is a sum of distance from objects to object center
19318                 disp = 0.0f;
19319                 ct = 0;
19320                 for(int i=0; i<N; i++) {
19321                         qm = 1.0e23f;
19322                         for(int k=0; k<K; k++) {
19323                                 if(float(i) == cent(k)) {
19324                                         qm = 0.0f;
19325                                         na = (float)k;
19326                                 } else {
19327                                         float dt = (*d)(mono(i,int(cent(k))));
19328                                         if(dt < qm) {
19329                                                 qm = dt;
19330                                                 na = (float)k;
19331                                         }
19332                                 }
19333                         }
19334 
19335 
19336                         // Simulated annealing
19337                         if(exp(-1.0/float(T)) > Util::get_irand(1,1000)/1000.0) {
19338                             na = (float)(Util::get_irand(0, K));
19339                             qm = (*d)(mono(i,int(na)));
19340                             ct++;
19341                         }
19342 
19343                         disp += qm;
19344 
19345                         if(na != assign(i)) {
19346                                 assign(i) = na;
19347                                 change = true;
19348                         }
19349                 }
19350 
19351                 //cout<<"Iteration:  "<<it<< " disp " <<disp << " T " << T << " disturb " << ct << endl;
19352                 T = T*F;
19353 
19354         //for(int k=0; k<N; k++) cout<<assign(k)<<"    ";cout<<endl;
19355                 //print disp
19356                 //print  assign
19357                 // find centers
19358                 for(int k=0; k<K; k++) {
19359                         qm = 1.0e23f;
19360                         for(int i=0; i<N; i++) {
19361                                 if(assign(i) == float(k)) {
19362                                         float q = 0.0;
19363                                         for(int j=0; j<N; j++) {
19364                                                 if(assign(j) == float(k)) {
19365                                                                 //it cannot be the same object
19366                                                         if(i != j)  q += (*d)(mono(i,j));
19367                                                         //cout<<q<<"   "<<i<<"   "<<j<<"   "<<k<<endl;}
19368                                                 }
19369                                         }
19370                                         if(q < qm) {
19371                                                 //cout<<qm<<"   "<<q<<"   "<<i<<"   "<<k<<endl;
19372                                                 qm = q;
19373                                                 cent(k) = float(i);
19374                                         }
19375                                 }
19376                         }
19377                 }
19378         //for(int k=0; k<K; k++) cout<<cent(k)<<"    ";cout<<endl;cout<<disp<<endl;
19379         }
19380         out[N+K] = disp;
19381         out[N+K+1] = float(it);
19382         return  out;
19383 }

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

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

Compute the discrepancy belong all common-lines

Definition at line 4916 of file util_sparx.cpp.

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

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

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

This function prepare rotation matrix for common-lines

Definition at line 4693 of file util_sparx.cpp.

References deg_rad.

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

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

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

This function calculate all common-lines in space for Voronoi

Definition at line 4861 of file util_sparx.cpp.

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

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

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

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

This function calculates common-lines between sinogram

Definition at line 4762 of file util_sparx.cpp.

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

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

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

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

This function calculates all common-lines between sinogram

Definition at line 4812 of file util_sparx.cpp.

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

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

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

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

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

Definition at line 4675 of file util_sparx.cpp.

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

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

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

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

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

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

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

this function update only one rotation amtrix according a new orientation

Definition at line 4731 of file util_sparx.cpp.

References deg_rad.

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

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

Definition at line 4585 of file util_sparx.cpp.

References Assert, PI2, and vrdg().

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

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

Definition at line 7155 of file util_sparx.cpp.

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

Referenced by hsortd().

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

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

Definition at line 7160 of file util_sparx.cpp.

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

Referenced by hsortd().

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

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

Definition at line 5346 of file util_sparx.cpp.

Referenced by cyclicshift(), and slicereverse().

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

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

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

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

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

References ENTERFUNC, EXITFUNC, and ssyev_().

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

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

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

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

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

Definition at line 3165 of file util_sparx.cpp.

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

03165                                                                                {
03166         //  neg = 0 straight,  neg = 1 mirrored
03167         int nring = numr.size()/3;
03168         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03169         int maxrin = numr[numr.size()-1];
03170         double qn;   float  tot;
03171         float *circ1 = circ1p->get_data();
03172         float *circ2 = circ2p->get_data();
03173 /*
03174 c checks single position, neg is flag for checking mirrored position
03175 c
03176 c  input - fourier transforms of rings!
03177 c  first set is conjugated (mirrored) if neg
03178 c  circ1 already multiplied by weights!
03179 c       automatic arrays
03180         dimension         t(maxrin)  removed +2 as it is only needed for other ffts
03181         double precision  q(maxrin)
03182         double precision  t7(-3:3)
03183 */
03184         float *t;
03185         double t7[7], *q;
03186         int    i, j, k, ip, jc, numr3i, numr2i, jtot = 0;
03187         float  pos;
03188 
03189 #ifdef _WIN32
03190         ip = -(int)(log((float)maxrin)/log(2.0f));
03191 #else
03192         ip = -(int) (log2(maxrin));
03193 #endif  //_WIN32
03194 
03195         q = (double*)calloc(maxrin, sizeof(double));
03196         t = (float*)calloc(maxrin, sizeof(float));
03197 
03198 //   cout << *qn <<"  " <<*tot<<"  "<<ip<<endl;
03199         for (i=1; i<=nring; i++) {
03200                 numr3i = numr(3,i);
03201                 numr2i = numr(2,i);
03202 
03203                 t(1) = (circ1(numr2i)) * circ2(numr2i);
03204 
03205                 if (numr3i != maxrin) {
03206                          // test .ne. first for speed on some compilers
03207                         t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1);
03208                         t(2)            = 0.0;
03209 
03210                         if (neg) {
03211                                 // first set is conjugated (mirrored)
03212                                 for (j=3;j<=numr3i;j=j+2) {
03213                                         jc = j+numr2i-1;
03214                                         t(j) =(circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1);
03215                                         t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc);
03216                                 }
03217                         } else {
03218                                 for (j=3;j<=numr3i;j=j+2) {
03219                                         jc = j+numr2i-1;
03220                                         t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1);
03221                                         t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc);
03222                                 }
03223                         }
03224                         for (j=1;j<=numr3i+1;j++) q(j) = q(j) + t(j);
03225                 } else {
03226                         t(2) = circ1(numr2i+1) * circ2(numr2i+1);
03227                         if (neg) {
03228                                 // first set is conjugated (mirrored)
03229                                 for (j=3;j<=maxrin;j=j+2) {
03230                                         jc = j+numr2i-1;
03231                                         t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1);
03232                                         t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc);
03233                                 }
03234                         } else {
03235                                 for (j=3;j<=maxrin;j=j+2) {
03236                                         jc = j+numr2i-1;
03237                                         t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1);
03238                                         t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc);
03239                                 }
03240                         }
03241                         for (j = 1; j <= maxrin; j++) q(j) += t(j);
03242                 }
03243         }
03244 
03245         fftr_d(q,ip);
03246 
03247         qn = -1.0e20;
03248         for (j=1;j<=maxrin;j++) {
03249            if (q(j) >= qn) {
03250                   qn = q(j); jtot = j;
03251            }
03252         }
03253 
03254         for (k=-3; k<=3; k++) {
03255                 j = (jtot+k+maxrin-1)%maxrin + 1;
03256                 t7(k+4) = q(j);
03257         }
03258 
03259         prb1d(t7,7,&pos);
03260 
03261         tot = (float)jtot + pos;
03262 
03263         if (q) free(q);
03264         if (t) free(t);
03265 
03266         Dict retvals;
03267         retvals["qn"] = qn;
03268         retvals["tot"] = tot;
03269         return  retvals;
03270 }

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

Definition at line 3272 of file util_sparx.cpp.

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

03272                                                                                                  {
03273    //  neg = 0 straight,  neg = 1 mirrored
03274         int nring = numr.size()/3;
03275         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03276         int maxrin = numr[numr.size()-1];
03277         double qn;   float  tot;
03278         float *circ1 = circ1p->get_data();
03279         float *circ2 = circ2p->get_data();
03280 /*
03281 c checks single position, neg is flag for checking mirrored position
03282 c
03283 c  input - fourier transforms of rings!
03284 c  first set is conjugated (mirrored) if neg
03285 c  multiplication by weights!
03286 c       automatic arrays
03287         dimension         t(maxrin)  removed +2 as it is only needed for other ffts
03288         double precision  q(maxrin)
03289         double precision  t7(-3:3)
03290 */
03291         float *t;
03292         double t7[7], *q;
03293         int    i, j, k, ip, jc, numr3i, numr2i, jtot = 0;
03294         float  pos;
03295 
03296 #ifdef _WIN32
03297         ip = -(int)(log((float)maxrin)/log(2.0f));
03298 #else
03299         ip = -(int) (log2(maxrin));
03300 #endif  //_WIN32
03301 
03302         q = (double*)calloc(maxrin, sizeof(double));
03303         t = (float*)calloc(maxrin, sizeof(float));
03304 
03305 //   cout << *qn <<"  " <<*tot<<"  "<<ip<<endl;
03306         for (i=1;i<=nring;i++) {
03307                 numr3i = numr(3,i);
03308                 numr2i = numr(2,i);
03309 
03310                 t(1) = circ1(numr2i) * circ2(numr2i);
03311 
03312                 if (numr3i != maxrin) {
03313                         // test .ne. first for speed on some compilers
03314                         t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1);
03315                         t(2)      = 0.0;
03316 
03317                         if (neg) {
03318                                 // first set is conjugated (mirrored)
03319                                 for (j=3; j<=numr3i; j=j+2) {
03320                                         jc = j+numr2i-1;
03321                                         t(j)   =  (circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1);
03322                                         t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc);
03323                                 }
03324                         } else {
03325                                 for (j=3; j<=numr3i; j=j+2) {
03326                                         jc = j+numr2i-1;
03327                                         t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1);
03328                                         t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc);
03329                                 }
03330                         }
03331                         for (j=1;j<=numr3i+1;j++) q(j) += t(j)*w[i-1];
03332                 } else {
03333                         t(2) = circ1(numr2i+1) * circ2(numr2i+1);
03334                         if (neg) {
03335                                 // first set is conjugated (mirrored)
03336                                 for (j=3; j<=maxrin; j=j+2) {
03337                                         jc = j+numr2i-1;
03338                                         t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1);
03339                                         t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc);
03340                                 }
03341                         } else {
03342                                 for (j=3; j<=maxrin; j=j+2) {
03343                                 jc = j+numr2i-1;
03344                                 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1);
03345                                 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc);
03346                                 }
03347                         }
03348                         for (j = 1; j <= maxrin; j++) q(j) += t(j)*w[i-1];
03349                 }
03350         }
03351 
03352         fftr_d(q,ip);
03353 
03354         qn = -1.0e20;
03355         for (j=1;j<=maxrin;j++) {
03356                 //cout << j << "  " << q(j) << endl;
03357                 if (q(j) >= qn) {
03358                         qn = q(j);
03359                         jtot = j;
03360                 }
03361         }
03362 
03363         for (k=-3; k<=3; k++) {
03364                 j = (jtot+k+maxrin-1)%maxrin + 1;
03365                 t7(k+4) = q(j);
03366         }
03367 
03368         prb1d(t7,7,&pos);
03369 
03370         tot = (float)jtot + pos;
03371 
03372         //if (q) free(q);
03373         if (t) free(t);
03374 
03375         Dict retvals;
03376         //tot = 1;
03377         //qn = q(1);
03378         retvals["qn"] = qn;
03379         retvals["tot"] = tot;
03380 
03381         if (q) free(q);
03382 
03383         return  retvals;
03384 }

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

Definition at line 3386 of file util_sparx.cpp.

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

Referenced by multiref_polar_ali_2d(), and multiref_polar_ali_2d_local().

03386                                                                       {
03387         int nring = numr.size()/3;
03388         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03389         int maxrin = numr[numr.size()-1];
03390         double qn; float tot; double qm; float tmt;
03391         float *circ1 = circ1p->get_data();
03392         float *circ2 = circ2p->get_data();
03393 /*
03394 c
03395 c  checks both straight & mirrored positions
03396 c
03397 c  input - fourier transforms of rings!!
03398 c  circ1 already multiplied by weights!
03399 c
03400 */
03401 
03402         // dimension             circ1(lcirc),circ2(lcirc)
03403 
03404         // t(maxrin), q(maxrin), t7(-3:3)  //maxrin+2 removed
03405         double *t, *q, t7[7];
03406 
03407         int   ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
03408         float t1, t2, t3, t4, c1, c2, d1, d2, pos;
03409 
03410         qn  = 0.0f;
03411         qm  = 0.0f;
03412         tot = 0.0f;
03413         tmt = 0.0f;
03414 #ifdef _WIN32
03415         ip = -(int)(log((float)maxrin)/log(2.0f));
03416 #else
03417         ip = -(int)(log2(maxrin));
03418 #endif  //_WIN32
03419   //for (j=1; j<=maxrin;j++) cout <<"  "<<j<<"   "<<circ1(j)<<"   "<<circ2(j) <<endl;
03420 
03421         //  c - straight  = circ1 * conjg(circ2)
03422         //  zero q array
03423 
03424         q = (double*)calloc(maxrin,sizeof(double));
03425 
03426         //   t - mirrored  = conjg(circ1) * conjg(circ2)
03427         //   zero t array
03428         t = (double*)calloc(maxrin,sizeof(double));
03429 
03430    //   premultiply  arrays ie( circ12 = circ1 * circ2) much slower
03431         for (i=1; i<=nring; i++) {
03432 
03433                 numr3i = numr(3,i);   // Number of samples of this ring
03434                 numr2i = numr(2,i);   // The beginning point of this ring
03435 
03436                 t1   = circ1(numr2i) * circ2(numr2i);
03437                 q(1) += t1;
03438                 t(1) += t1;
03439 
03440                 t1   = circ1(numr2i+1) * circ2(numr2i+1);
03441                 if (numr3i == maxrin)  {
03442                         q(2) += t1;
03443                         t(2) += t1;
03444                 } else {
03445                         q(numr3i+1) += t1;
03446                         t(numr3i+1) += t1;
03447                 }
03448 
03449                 for (j=3; j<=numr3i; j += 2) {
03450                         jc     = j+numr2i-1;
03451 
03452 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03453 //                                ----- -----    ----- -----
03454 //                                 t1     t2      t3    t4
03455 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i
03456 //                                    ----- -----    ----- -----
03457 //                                     t1    t2       t3    t4
03458 
03459                         c1     = circ1(jc);
03460                         c2     = circ1(jc+1);
03461                         d1     = circ2(jc);
03462                         d2     = circ2(jc+1);
03463 
03464                         t1     = c1 * d1;
03465                         t2     = c2 * d2;
03466                         t3     = c1 * d2;
03467                         t4     = c2 * d1;
03468 
03469                         q(j)   += t1 + t2;
03470                         q(j+1) += -t3 + t4;
03471                         t(j)   += t1 - t2;
03472                         t(j+1) += -t3 - t4;
03473                 }
03474         }
03475         //for (j=1; j<=maxrin; j++) cout <<"  "<<j<<"   "<<q(j) <<"   "<<t(j) <<endl;
03476         fftr_d(q,ip);
03477 
03478         qn  = -1.0e20;
03479         for (j=1; j<=maxrin; j++) {//cout <<"  "<<j<<"   "<<q(j) <<endl;
03480                 if (q(j) >= qn) {
03481                         qn  = q(j);
03482                         jtot = j;
03483                 }
03484         }
03485 
03486         for (k=-3; k<=3; k++) {
03487                 j = ((jtot+k+maxrin-1)%maxrin)+1;
03488                 t7(k+4) = q(j);
03489         }
03490 
03491         // interpolate
03492         prb1d(t7,7,&pos);
03493         tot = (float)(jtot)+pos;
03494         // Do not interpolate
03495         //tot = (float)(jtot);
03496 
03497         // mirrored
03498         fftr_d(t,ip);
03499 
03500         // find angle
03501         qm = -1.0e20;
03502         for (j=1; j<=maxrin;j++) {//cout <<"  "<<j<<"   "<<t(j) <<endl;
03503                 if ( t(j) >= qm ) {
03504                         qm   = t(j);
03505                         jtot = j;
03506                 }
03507         }
03508 
03509         for (k=-3; k<=3; k++)  {
03510                 j = ((jtot+k+maxrin-1)%maxrin) + 1;
03511                 t7(k+4) = t(j);
03512         }
03513 
03514         // interpolate
03515 
03516         prb1d(t7,7,&pos);
03517         tmt = float(jtot) + pos;
03518         // Do not interpolate
03519         //tmt = float(jtot);
03520 
03521         free(t);
03522         free(q);
03523 
03524         Dict retvals;
03525         retvals["qn"] = qn;
03526         retvals["tot"] = tot;
03527         retvals["qm"] = qm;
03528         retvals["tmt"] = tmt;
03529         return retvals;
03530 }

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

Definition at line 3532 of file util_sparx.cpp.

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

Referenced by multiref_polar_ali_2d_delta().

03532                                                                                                             {
03533         int nring = numr.size()/3;
03534         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03535         int maxrin = numr[numr.size()-1];
03536         double qn; float tot; double qm; float tmt;
03537         float *circ1 = circ1p->get_data();
03538         float *circ2 = circ2p->get_data();
03539 /*
03540 c
03541 c  checks both straight & mirrored positions
03542 c
03543 c  input - fourier transforms of rings!!
03544 c  circ1 already multiplied by weights!
03545 c
03546 */
03547 
03548         // dimension             circ1(lcirc),circ2(lcirc)
03549 
03550         // t(maxrin), q(maxrin), t7(-3:3)  //maxrin+2 removed
03551         double *t, *q;
03552 
03553         int   ip, jc, numr3i, numr2i, i, j, jtot = 0;
03554         float t1, t2, t3, t4, c1, c2, d1, d2;
03555 
03556         qn  = 0.0f;
03557         qm  = 0.0f;
03558         tot = 0.0f;
03559         tmt = 0.0f;
03560 #ifdef _WIN32
03561         ip = -(int)(log((float)maxrin)/log(2.0f));
03562 #else
03563         ip = -(int)(log2(maxrin));
03564 #endif  //_WIN32
03565   //for (j=1; j<=maxrin;j++) cout <<"  "<<j<<"   "<<circ1(j)<<"   "<<circ2(j) <<endl;
03566 
03567         //  c - straight  = circ1 * conjg(circ2)
03568         //  zero q array
03569 
03570         q = (double*)calloc(maxrin,sizeof(double));
03571 
03572         //   t - mirrored  = conjg(circ1) * conjg(circ2)
03573         //   zero t array
03574         t = (double*)calloc(maxrin,sizeof(double));
03575 
03576    //   premultiply  arrays ie( circ12 = circ1 * circ2) much slower
03577         for (i=1; i<=nring; i++) {
03578 
03579                 numr3i = numr(3,i);   // Number of samples of this ring
03580                 numr2i = numr(2,i);   // The beginning point of this ring
03581 
03582                 t1   = circ1(numr2i) * circ2(numr2i);
03583                 q(1) += t1;
03584                 t(1) += t1;
03585 
03586                 t1   = circ1(numr2i+1) * circ2(numr2i+1);
03587                 if (numr3i == maxrin)  {
03588                         q(2) += t1;
03589                         t(2) += t1;
03590                 } else {
03591                         q(numr3i+1) += t1;
03592                         t(numr3i+1) += t1;
03593                 }
03594 
03595                 for (j=3; j<=numr3i; j += 2) {
03596                         jc     = j+numr2i-1;
03597 
03598 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03599 //                                ----- -----    ----- -----
03600 //                                 t1     t2      t3    t4
03601 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i
03602 //                                    ----- -----    ----- -----
03603 //                                     t1    t2       t3    t4
03604 
03605                         c1     = circ1(jc);
03606                         c2     = circ1(jc+1);
03607                         d1     = circ2(jc);
03608                         d2     = circ2(jc+1);
03609 
03610                         t1     = c1 * d1;
03611                         t2     = c2 * d2;
03612                         t3     = c1 * d2;
03613                         t4     = c2 * d1;
03614 
03615                         q(j)   += t1 + t2;
03616                         q(j+1) += -t3 + t4;
03617                         t(j)   += t1 - t2;
03618                         t(j+1) += -t3 - t4;
03619                 }
03620         }
03621         //for (j=1; j<=maxrin; j++) cout <<"  "<<j<<"   "<<q(j) <<"   "<<t(j) <<endl;
03622         fftr_d(q,ip);
03623 
03624         qn  = -1.0e20;
03625 
03626         int jstart = 1+static_cast<int>(delta_start/360.0*maxrin);
03627         int jstep = static_cast<int>(delta/360.0*maxrin);
03628         if (jstep < 1) { jstep = 1; }
03629 
03630         for (j=jstart; j<=maxrin; j+=jstep) {//cout <<"  "<<j<<"   "<<q(j) <<endl;
03631                 if (q(j) >= qn) {
03632                         qn  = q(j);
03633                         jtot = j;
03634                 }
03635         }
03636 
03637         //for (k=-3; k<=3; k++) {
03638         //      j = ((jtot+k+maxrin-1)%maxrin)+1;
03639         //      t7(k+4) = q(j);
03640         //}
03641 
03642         // interpolate
03643         //prb1d(t7,7,&pos);
03644         //tot = (float)(jtot)+pos;
03645         // Do not interpolate
03646         tot = (float)(jtot);
03647 
03648         // mirrored
03649         fftr_d(t,ip);
03650 
03651         // find angle
03652         qm = -1.0e20;
03653         for (j=jstart; j<=maxrin;j+=jstep) {//cout <<"  "<<j<<" "<<t(j) <<endl;
03654                 if ( t(j) >= qm ) {
03655                         qm   = t(j);
03656                         jtot = j;
03657                 }
03658         }
03659 
03660         //for (k=-3; k<=3; k++)  {
03661         //      j = ((jtot+k+maxrin-1)%maxrin) + 1;
03662         //      t7(k+4) = t(j);
03663         //}
03664 
03665         // interpolate
03666 
03667         //prb1d(t7,7,&pos);
03668         //tmt = float(jtot) + pos;
03669         // Do not interpolate
03670         tmt = float(jtot);
03671 
03672         free(t);
03673         free(q);
03674 
03675         Dict retvals;
03676         retvals["qn"] = qn;
03677         retvals["tot"] = tot;
03678         retvals["qm"] = qm;
03679         retvals["tmt"] = tmt;
03680         return retvals;
03681 }

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

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

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

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

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

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

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

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

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

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

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

Definition at line 4182 of file util_sparx.cpp.

References circ1b, circ2b, fftr_q(), EMAN::EMData::get_data(), log(), numr, q, and t.

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

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

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

Definition at line 4167 of file util_sparx.cpp.

References Crosrng_msg_vec().

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

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

Definition at line 3979 of file util_sparx.cpp.

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

Referenced by multiref_polar_ali_2d_nom().

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

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

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

Definition at line 3684 of file util_sparx.cpp.

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

Referenced by multiref_polar_ali_helical().

03684                                                                                             {
03685         int nring = numr.size()/3;
03686         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03687         int maxrin = numr[numr.size()-1];
03688         double qn; float tot; double qm; float tmt;
03689         float *circ1 = circ1p->get_data();
03690         float *circ2 = circ2p->get_data();
03691 
03692         // dimension             circ1(lcirc),circ2(lcirc)
03693 
03694         // t(maxrin), q(maxrin), t7(-3:3)  //maxrin+2 removed
03695         double *t, *q, t7[7];
03696 
03697         int   ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
03698         float t1, t2, t3, t4, c1, c2, d1, d2, pos;
03699 
03700         qn  = 0.0f;
03701         qm  = 0.0f;
03702         tot = 0.0f;
03703         tmt = 0.0f;
03704 #ifdef _WIN32
03705         ip = -(int)(log((float)maxrin)/log(2.0f));
03706 #else
03707         ip = -(int)(log2(maxrin));
03708 #endif  //_WIN32
03709   //for (j=1; j<=maxrin;j++) cout <<"  "<<j<<"   "<<circ1(j)<<"   "<<circ2(j) <<endl;
03710 
03711         //  c - straight  = circ1 * conjg(circ2)
03712         //  zero q array
03713 
03714         q = (double*)calloc(maxrin,sizeof(double));
03715 
03716         //   t - mirrored  = conjg(circ1) * conjg(circ2)
03717         //   zero t array
03718         t = (double*)calloc(maxrin,sizeof(double));
03719 
03720    //   premultiply  arrays ie( circ12 = circ1 * circ2) much slower
03721         for (i=1; i<=nring; i++) {
03722 
03723                 numr3i = numr(3,i);   // Number of samples of this ring
03724                 numr2i = numr(2,i);   // The beginning point of this ring
03725 
03726                 t1   = circ1(numr2i) * circ2(numr2i);
03727                 q(1) += t1;
03728                 t(1) += t1;
03729 
03730                 t1   = circ1(numr2i+1) * circ2(numr2i+1);
03731                 if (numr3i == maxrin)  {
03732                         q(2) += t1;
03733                         t(2) += t1;
03734                 } else {
03735                         q(numr3i+1) += t1;
03736                         t(numr3i+1) += t1;
03737                 }
03738 
03739                 for (j=3; j<=numr3i; j += 2) {
03740                         jc     = j+numr2i-1;
03741 
03742 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03743 //                                ----- -----    ----- -----
03744 //                                 t1     t2      t3    t4
03745 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i
03746 //                                    ----- -----    ----- -----
03747 //                                     t1    t2       t3    t4
03748 
03749                         c1     = circ1(jc);
03750                         c2     = circ1(jc+1);
03751                         d1     = circ2(jc);
03752                         d2     = circ2(jc+1);
03753 
03754                         t1     = c1 * d1;
03755                         t2     = c2 * d2;
03756                         t3     = c1 * d2;
03757                         t4     = c2 * d1;
03758 
03759                         q(j)   += t1 + t2;
03760                         q(j+1) += -t3 + t4;
03761                         t(j)   += t1 - t2;
03762                         t(j+1) += -t3 - t4;
03763                 }
03764         }
03765         //for (j=1; j<=maxrin; j++) cout <<"  "<<j<<"   "<<q(j) <<"   "<<t(j) <<endl;
03766         fftr_d(q,ip);
03767 
03768         int psi_range  = int(psi_max/360.0*maxrin+0.5);
03769         const int psi_0 = 0;
03770         int psi_180    = int(  180.0/360.0*maxrin+0.5);
03771 
03772         qn  = -1.0e20;
03773         for (k=-psi_range; k<=psi_range; k++) {
03774                 j = (k+psi_0+maxrin-1)%maxrin+1;//string modemo = "f";cout <<" 90   "<<j<<"   "<<ang_n(j,modemo,maxrin) <<"  "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03775                 if (q(j) >= qn) {
03776                         qn  = q(j);
03777                         jtot = j;
03778                 }
03779         }
03780 
03781         for (k=-psi_range; k<=psi_range; k++) {
03782                 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270  "<<j<<"  "<<ang_n(j,modemo,maxrin) <<"  "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03783                 if (q(j) >= qn) {
03784                         qn  = q(j);
03785                         jtot = j;
03786                 }
03787         }
03788 
03789         for (k=-3; k<=3; k++) {
03790                 j = ((jtot+k+maxrin-1)%maxrin)+1;
03791                 t7(k+4) = q(j);
03792         }
03793 
03794         // interpolate
03795         prb1d(t7,7,&pos);
03796         tot = (float)(jtot)+pos;
03797         // Do not interpolate
03798         //tot = (float)(jtot);
03799 
03800         // mirrored
03801         fftr_d(t,ip);
03802 
03803         // find angle
03804         qm = -1.0e20;
03805         for (k=-psi_range; k<=psi_range; k++) {
03806                 j = (k+psi_0+maxrin-1)%maxrin+1;//string modemo = "f";cout <<" 90   "<<j<<"   "<<ang_n(j,modemo,maxrin) <<"  "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03807                 if (t(j) >= qm) {
03808                         qm  = t(j);
03809                         jtot = j;
03810                 }
03811         }
03812 
03813         for (k=-psi_range; k<=psi_range; k++) {
03814                 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270  "<<j<<"  "<<ang_n(j,modemo,maxrin) <<"  "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03815                 if (t(j) >= qm) {
03816                         qm  = t(j);
03817                         jtot = j;
03818                 }
03819         }
03820 
03821         for (k=-3; k<=3; k++)  {
03822                 j = ((jtot+k+maxrin-1)%maxrin) + 1;
03823                 t7(k+4) = t(j);
03824         }
03825 
03826         // interpolate
03827 
03828         prb1d(t7,7,&pos);
03829         tmt = float(jtot) + pos;
03830         // Do not interpolate
03831         //tmt = float(jtot);
03832 
03833         free(t);
03834         free(q);
03835 
03836         Dict retvals;
03837         retvals["qn"] = qn;
03838         retvals["tot"] = tot;
03839         retvals["qm"] = qm;
03840         retvals["tmt"] = tmt;
03841         return retvals;
03842 }

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

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

Definition at line 3845 of file util_sparx.cpp.

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

Referenced by multiref_polar_ali_2d_local_psi().

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

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

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

19160 {
19161         int   ix, iy, iz;
19162         int   i,  j, k;
19163         int   nr2, nl2;
19164         float  dzz, az, ak;
19165         float  scx, scy, scz;
19166         int offset = 2 - nx%2;
19167         int lsm = nx + offset;
19168         EMData* ctf_img1 = new EMData();
19169         ctf_img1->set_size(lsm, ny, nz);
19170         float freq = 1.0f/(2.0f*ps);
19171         scx = 2.0f/float(nx);
19172         if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f;
19173         if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f;
19174         nr2 = ny/2 ;
19175         nl2 = nz/2 ;
19176         for ( k=0; k<nz;k++) {
19177                 iz = k;  if(k>nl2) iz=k-nz;
19178                 for ( j=0; j<ny;j++) {
19179                         iy = j;  if(j>nr2) iy=j - ny;
19180                         for ( i=0; i<lsm/2; i++) {
19181                                 ix=i;
19182                                 ak=pow(ix*ix*scx*scx+iy*scy*iy*scy+iz*scz*iz*scz, 0.5f)*freq;
19183                                 if(ak!=0) az=0.0; else az=M_PI;
19184                                 dzz = dz + dza/2.0f*sin(2*(az-azz*M_PI/180.0f));
19185                                 (*ctf_img1) (i*2,j,k)   = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign);
19186                                 (*ctf_img1) (i*2+1,j,k) = 0.0f;
19187                         }
19188                 }
19189         }
19190         ctf_img1->update();
19191         ctf_img1->set_complex(true);
19192         ctf_img1->set_ri(true);
19193         //ctf_img1->attr_dict["is_complex"] = 1;
19194         //ctf_img1->attr_dict["is_ri"] = 1;
19195         if(nx%2==0) ctf_img1->set_fftodd(false); else ctf_img1->set_fftodd(true);
19196         return ctf_img1;
19197 }

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

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

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

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

Definition at line 5160 of file util_sparx.cpp.

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

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

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

Definition at line 7671 of file util_sparx.cpp.

References ENTERFUNC, and EXITFUNC.

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

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

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

17631 {
17632         ENTERFUNC;
17633         /* Exception Handle */
17634         if (!img) {
17635                 throw NullPointerException("NULL input image");
17636         }
17637         /* ========= img /= img1 ===================== */
17638 
17639         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17640         int size = nx*ny*nz;
17641         float *img_ptr  = img->get_data();
17642         float *img1_ptr = img1->get_data();
17643         if(img->is_complex()) {
17644                 for (int i=0; i<size; i+=2) {
17645                         if(img1_ptr[i] > 1.e-10f) {
17646                         img_ptr[i]   /= img1_ptr[i];
17647                         img_ptr[i+1] /= img1_ptr[i];
17648                         } else img_ptr[i] = img_ptr[i+1] = 0.0f;
17649                 }
17650         } else throw ImageFormatException("Only Fourier image allowed");
17651 
17652         img->update();
17653 
17654         EXITFUNC;
17655 }

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

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

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

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

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

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

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

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

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

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

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

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

Definition at line 4407 of file util_sparx.cpp.

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

Referenced by ener_tot().

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

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

Definition at line 4427 of file util_sparx.cpp.

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

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

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

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

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

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 1221 of file util.cpp.

References x, and y.

Referenced by EMAN::Symmetry3D::cache_au_planes().

01222 {
01223         int x=0,y=1,z=2;
01224         plane[0] = p1[y]*(p2[z]-p3[z])+p2[y]*(p3[z]-p1[z])+p3[y]*(p1[z]-p2[z]);
01225         plane[1] = p1[z]*(p2[x]-p3[x])+p2[z]*(p3[x]-p1[x])+p3[z]*(p1[x]-p2[x]);
01226         plane[2] = p1[x]*(p2[y]-p3[y])+p2[x]*(p3[y]-p1[y])+p3[x]*(p1[y]-p2[y]);
01227         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]);
01228         plane[3] = -plane[3];
01229 }

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

Definition at line 7019 of file util_sparx.cpp.

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

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

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

References angles, dgr_to_rad, phi, and theta.

00508 {
00509         vector<float> angles;
00510         float psi = 0.0;
00511         if ((0.0 == t1)&&(0.0 == t2)||(t1 >= t2)) {
00512                 t1 = 0.0f;
00513                 t2 = 90.0f;
00514         }
00515         if ((0.0 == p1)&&(0.0 == p2)||(p1 >= p2)) {
00516                 p1 = 0.0f;
00517                 p2 = 359.9f;
00518         }
00519         bool skip = ((t1 < 90.0)&&(90.0 == t2)&&(0.0 == p1)&&(p2 > 180.0));
00520         for (float theta = t1; theta <= t2; theta += delta) {
00521                 float detphi;
00522                 int lt;
00523                 if ((0.0 == theta)||(180.0 == theta)) {
00524                         detphi = 360.0f;
00525                         lt = 1;
00526                 } else {
00527                         detphi = delta/sin(theta*static_cast<float>(dgr_to_rad));
00528                         lt = int((p2 - p1)/detphi)-1;
00529                         if (lt < 1) lt = 1;
00530                         detphi = (p2 - p1)/lt;
00531                 }
00532                 for (int i = 0; i < lt; i++) {
00533                         float phi = p1 + i*detphi;
00534                         if (skip&&(90.0 == theta)&&(phi > 180.0)) continue;
00535                         angles.push_back(phi);
00536                         angles.push_back(theta);
00537                         angles.push_back(psi);
00538                 }
00539         }
00540         return angles;
00541 }

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

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

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

Definition at line 20300 of file util_sparx.cpp.

References k_means_cont_table_().

Referenced by initial_prune().

20300                                                                                                                                                                                 {
20301 
20302 
20303         if (size_next <= T) return 0;
20304 
20305         // take the intx of next and cur
20306         int* curintx2(0);
20307         int nintx = Util::k_means_cont_table_(curintx, next+2, curintx2, size_curintx, size_next,0);
20308         if (nintx <= T) return 0;
20309 
20310         int old_depth=depth;
20311         if (depth == partref) depth = depth + 1; // we skip classes in partref
20312         if (depth == (nParts)) { if (old_depth>0) return 1;}
20313 
20314         // have not yet reached a leaf, and current weight is still greather than T, so keep on going.
20315 
20316         curintx2 = new int[nintx]; // put the intersection set in here
20317         Util::k_means_cont_table_(curintx,next+2,curintx2, size_curintx, size_next,1);
20318 
20319         // if (old_depth > 0) {delete[] curintx;} // don't delete when depth == 0 because curintx in that case is a pointer into Parts
20320 
20321         // we now consider each of the classes in partition (depth+1) in turn
20322         bool gt_thresh;
20323         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
20324 
20325         for (int i=0; i < num_classes; i++){
20326                 if (*(Parts[depth][i]+1) < 1) continue; // class is not active so move on
20327                 size_next = (*(dimClasses + depth*K+(*(Parts[depth][i])) ))-2;
20328                 gt_thresh = explore(Parts,dimClasses, nParts, K, T, partref, curintx2,nintx, Parts[depth][i], size_next, depth+1);
20329                 if (gt_thresh) return 1;
20330         }
20331         delete[] curintx2;
20332         return 0;
20333 }

int * Util::explore2 int *  argParts,
int *  Indices,
int *  dimClasses,
int  nParts,
int  K,
int  newT,
int *  curintx,
int  size_curintx,
int *  next,
int  size_next,
int  depth
[static]
 

Definition at line 20149 of file util_sparx.cpp.

References explore2(), and k_means_cont_table_().

20149                                                                                                                                                                  {
20150 // depth is the level which is going to be explored in the current iteration
20151         int* curintx2(0);
20152 
20153         int nintx = size_curintx;
20154 
20155         // take the intx of next and cur
20156         if (depth >0){
20157                 nintx = Util::k_means_cont_table_(curintx,next, curintx2, size_curintx, size_next,0);
20158                 if (nintx <= newT) {curintx2 = new int[1]; *curintx2=0;return curintx2;}
20159         }
20160 
20161         // we're at a leaf so return.
20162         if (depth == (nParts-1)) { curintx2 = new int[1]; *curintx2 = nintx; return curintx2;}
20163 
20164 
20165         // have not yet reached a leaf, and current weight is still greather than T, so keep on going.
20166 
20167         if (depth > 0){
20168                 curintx2 = new int[nintx]; // put the intersection set in here
20169                 Util::k_means_cont_table_(curintx,next,curintx2, size_curintx, size_next,1);
20170         }
20171 
20172         if (depth == 0){
20173                 // set curintx2 to curintx
20174                 curintx2 = new int[size_curintx];
20175                 for (int cp = 0; cp < size_curintx; cp++) *(curintx2+cp) = *(curintx+cp);
20176         }
20177 
20178 
20179         // recursion (non-leaf case)
20180         depth=depth+1;
20181         int* curmax = new int[nParts-depth+1];
20182         *curmax=0;
20183         int* ret;
20184         // we now consider each of the classes in partition depth in turn
20185         for (int i=0; i < K; i++){
20186 
20187                 if (*(argParts + Indices[depth*K+i] + 1) < 1) continue; // class is not active so move on
20188                 size_next = (*(dimClasses + depth*K+i ))-2;
20189                 if (size_next <= newT) continue;
20190                 ret = Util::explore2(argParts,Indices, dimClasses, nParts, K, newT, curintx2, nintx, argParts + Indices[depth*K+i] + 2, size_next, depth);
20191                 if (*ret > *curmax && *ret > newT){
20192                         *curmax = *ret;
20193                         *(curmax+1)=i;
20194                         for (int j=0; j<nParts-depth-1; j++) { *(curmax+2 + j) = *(ret+1+j);}
20195                 }
20196                 delete[] ret;
20197         }
20198 
20199         delete[] curintx2;
20200         return curmax;
20201 }

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

Definition at line 1685 of file util_sparx.cpp.

References EMAN::EMData::cmplx(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, and round().

01685                                                                                                                    {
01686 
01687         int nxreal = nx - 2;
01688         if (nxreal != ny)
01689                 throw ImageDimensionException("extractpoint requires ny == nx");
01690         int nhalf = nxreal/2;
01691         bool flip = (nuxnew < 0.f);
01692         if (flip) {
01693                 nuxnew *= -1;
01694                 nuynew *= -1;
01695         }
01696         if (nuynew >= nhalf-0.5)  {
01697                 nuynew -= nxreal;
01698         } else if (nuynew < -nhalf-0.5) {
01699                 nuynew += nxreal;
01700         }
01701 
01702         // put (xnew,ynew) on a grid.  The indices will be wrong for
01703         // the Fourier elements in the image, but the grid sizing will
01704         // be correct.
01705         int ixn = int(Util::round(nuxnew));
01706         int iyn = int(Util::round(nuynew));
01707 
01708         // set up some temporary weighting arrays
01709         static float wy[7];
01710         static float wx[7];
01711 
01712         float iynn = nuynew - iyn;
01713         wy[0] = kb.i0win_tab(iynn+3);
01714         wy[1] = kb.i0win_tab(iynn+2);
01715         wy[2] = kb.i0win_tab(iynn+1);
01716         wy[3] = kb.i0win_tab(iynn);
01717         wy[4] = kb.i0win_tab(iynn-1);
01718         wy[5] = kb.i0win_tab(iynn-2);
01719         wy[6] = kb.i0win_tab(iynn-3);
01720 
01721         float ixnn = nuxnew - ixn;
01722         wx[0] = kb.i0win_tab(ixnn+3);
01723         wx[1] = kb.i0win_tab(ixnn+2);
01724         wx[2] = kb.i0win_tab(ixnn+1);
01725         wx[3] = kb.i0win_tab(ixnn);
01726         wx[4] = kb.i0win_tab(ixnn-1);
01727         wx[5] = kb.i0win_tab(ixnn-2);
01728         wx[6] = kb.i0win_tab(ixnn-3);
01729 
01730         float wsum = (wx[0]+wx[1]+wx[2]+wx[3]+wx[4]+wx[5]+wx[6])*(wy[0]+wy[1]+wy[2]+wy[3]+wy[4]+wy[5]+wy[6]);
01731 
01732         complex<float> result(0.f,0.f);
01733         if ((ixn >= 3) && (ixn <= nhalf-3) && (iyn >= -nhalf+3) && (iyn <= nhalf-4)) {
01734                 // (xin,yin) not within window border from the edge
01735                 for (int iy = 0; iy < 7; iy++) {
01736                         int iyp = iyn + iy - 3 ;
01737                         for (int ix = 0; ix < 7; ix++) {
01738                                 int ixp = ixn + ix - 3;
01739                                 float w = wx[ix]*wy[iy];
01740                                 complex<float> val = fimage->cmplx(ixp,iyp);
01741                                 result += val*w;
01742                         }
01743                 }
01744         } else {
01745                 // points that "stick out"
01746                 for (int iy = 0; iy < 7; iy++) {
01747                         int iyp = iyn + iy - 3;
01748                         for (int ix = 0; ix < 7; ix++) {
01749                                 int ixp = ixn + ix - 3;
01750                                 bool mirror = false;
01751                                 int ixt = ixp, iyt = iyp;
01752                                 if (ixt < 0) {
01753                                         ixt = -ixt;
01754                                         iyt = -iyt;
01755                                         mirror = !mirror;
01756                                 }
01757                                 if (ixt > nhalf) {
01758                                         ixt = nxreal - ixt;
01759                                         iyt = -iyt;
01760                                         mirror = !mirror;
01761                                 }
01762                                 if (iyt > nhalf-1)  iyt -= nxreal;
01763                                 if (iyt < -nhalf)   iyt += nxreal;
01764                                 float w = wx[ix]*wy[iy];
01765                                 complex<float> val = fimage->cmplx(ixt,iyt);
01766                                 if (mirror)  result += conj(val)*w;
01767                                 else         result += val*w;
01768                         }
01769                 }
01770         }
01771         if (flip)  result = conj(result)/wsum;
01772         else result /= wsum;
01773         return result;
01774 }

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

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

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

Definition at line 781 of file util.cpp.

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

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

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

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

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

00765                                    {
00766 static float *mem = (float *)malloc(sizeof(float)*1000);
00767 static bool needinit=true;
00768 
00769 if (needinit) {
00770         needinit=false;
00771         for (int i=0; i<1000; i++) mem[i]=(float)exp(-i/50.0);
00772 }
00773 if (f>0 || f<-19.98) return exp(f);
00774 int g=(int)(-f*50.0+0.5);
00775 
00776 return mem[g];
00777 }

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

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

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

Definition at line 1671 of file util.h.

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

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

Definition at line 2618 of file util_sparx.cpp.

References abs, bi, br, sgn(), status, t, and tab1.

Referenced by fftr_d().

02619 {
02620         double rni,sgn,tr1,tr2,ti1,ti2;
02621         double cc,c,ss,s,t,x2,x3,x4,x5;
02622         int    b3,b4,b5,b6,b7,b56;
02623         int    n, k, l, j, i, ix0, ix1, status=0;
02624 
02625         const double tab1[] = {
02626                 9.58737990959775e-5,
02627                 1.91747597310703e-4,
02628                 3.83495187571395e-4,
02629                 7.66990318742704e-4,
02630                 1.53398018628476e-3,
02631                 3.06795676296598e-3,
02632                 6.13588464915449e-3,
02633                 1.22715382857199e-2,
02634                 2.45412285229123e-2,
02635                 4.90676743274181e-2,
02636                 9.80171403295604e-2,
02637                 1.95090322016128e-1,
02638                 3.82683432365090e-1,
02639                 7.07106781186546e-1,
02640                 1.00000000000000,
02641         };
02642 
02643         n=(int)pow(2.0f,ln);
02644 
02645         k=abs(ks);
02646         l=16-ln;
02647         b3=n*k;
02648         b6=b3;
02649         b7=k;
02650         if (ks > 0) {
02651                 sgn=1.0f;
02652         } else {
02653                 sgn=-1.0f;
02654                 rni=1.0f/(float)(n);
02655                 j=1;
02656                 for (i=1; i<=n; i++) {
02657                         br(j)=br(j)*rni;
02658                         bi(j)=bi(j)*rni;
02659                         j=j+k;
02660                 }
02661         }
02662 
02663 L12:
02664    b6=b6/2;
02665    b5=b6;
02666    b4=2*b6;
02667    b56=b5-b6;
02668 
02669 L14:
02670    tr1=br(b5+1);
02671    ti1=bi(b5+1);
02672    tr2=br(b56+1);
02673    ti2=bi(b56+1);
02674 
02675    br(b5+1)=tr2-tr1;
02676    bi(b5+1)=ti2-ti1;
02677    br(b56+1)=tr1+tr2;
02678    bi(b56+1)=ti1+ti2;
02679 
02680    b5=b5+b4;
02681    b56=b5-b6;
02682    if ( b5 <= b3 )  goto  L14;
02683    if ( b6 == b7 )  goto  L20;
02684 
02685    b4=b7;
02686    cc=2.0f*pow(tab1(l),2);
02687    c=1.0f-cc;
02688    l++;
02689    ss=sgn*tab1(l);
02690    s=ss;
02691 
02692 L16:
02693    b5=b6+b4;
02694    b4=2*b6;
02695    b56=b5-b6;
02696 
02697 L18:
02698    tr1=br(b5+1);
02699    ti1=bi(b5+1);
02700    tr2=br(b56+1);
02701    ti2=bi(b56+1);
02702    br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1);
02703    bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1);
02704    br(b56+1)=tr1+tr2;
02705    bi(b56+1)=ti1+ti2;
02706 
02707    b5=b5+b4;
02708    b56=b5-b6;
02709    if ( b5 <= b3 )  goto  L18;
02710    b4=b5-b6;
02711    b5=b4-b3;
02712    c=-c;
02713    b4=b6-b5;
02714    if ( b5 < b4 )  goto  L16;
02715    b4=b4+b7;
02716    if ( b4 >= b5 ) goto  L12;
02717 
02718    t=c-cc*c-ss*s;
02719    s=s+ss*c-cc*s;
02720    c=t;
02721    goto  L16;
02722 
02723 L20:
02724    ix0=b3/2;
02725    b3=b3-b7;
02726    b4=0;
02727    b5=0;
02728    b6=ix0;
02729    ix1=0;
02730    if (b6 == b7) goto EXIT;
02731 
02732 L22:
02733    b4=b3-b4;
02734    b5=b3-b5;
02735    x2=br(b4+1);
02736    x3=br(b5+1);
02737    x4=bi(b4+1);
02738    x5=bi(b5+1);
02739    br(b4+1)=x3;
02740    br(b5+1)=x2;
02741    bi(b4+1)=x5;
02742    bi(b5+1)=x4;
02743    if(b6 < b4)  goto  L22;
02744 
02745 L24:
02746    b4=b4+b7;
02747    b5=b6+b5;
02748    x2=br(b4+1);
02749    x3=br(b5+1);
02750    x4=bi(b4+1);
02751    x5=bi(b5+1);
02752    br(b4+1)=x3;
02753    br(b5+1)=x2;
02754    bi(b4+1)=x5;
02755    bi(b5+1)=x4;
02756    ix0=b6;
02757 
02758 L26:
02759    ix0=ix0/2;
02760    ix1=ix1-ix0;
02761    if( ix1 >= 0)  goto L26;
02762 
02763    ix0=2*ix0;
02764    b4=b4+b7;
02765    ix1=ix1+ix0;
02766    b5=ix1;
02767    if ( b5 >= b4)  goto  L22;
02768    if ( b4 < b6)   goto  L24;
02769 
02770 EXIT:
02771    status = 0;
02772 }

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

Definition at line 2775 of file util_sparx.cpp.

References abs, bi, br, sgn(), status, t, and tab1.

Referenced by fftr_q().

02776 {
02777         //  dimension  br(1),bi(1)
02778 
02779         int b3,b4,b5,b6,b7,b56;
02780         int n, k, l, j, i, ix0, ix1;
02781         float rni, tr1, ti1, tr2, ti2, cc, c, ss, s, t, x2, x3, x4, x5, sgn;
02782         int status=0;
02783 
02784         const float tab1[] = {
02785                 9.58737990959775e-5f,
02786                 1.91747597310703e-4f,
02787                 3.83495187571395e-4f,
02788                 7.66990318742704e-4f,
02789                 1.53398018628476e-3f,
02790                 3.06795676296598e-3f,
02791                 6.13588464915449e-3f,
02792                 1.22715382857199e-2f,
02793                 2.45412285229123e-2f,
02794                 4.90676743274181e-2f,
02795                 9.80171403295604e-2f,
02796                 1.95090322016128e-1f,
02797                 3.82683432365090e-1f,
02798                 7.07106781186546e-1f,
02799                 1.00000000000000f,
02800         };
02801 
02802         n=(int)pow(2.0f,ln);
02803 
02804         k=abs(ks);
02805         l=16-ln;
02806         b3=n*k;
02807         b6=b3;
02808         b7=k;
02809         if( ks > 0 ) {
02810                 sgn=1.0f;
02811         } else {
02812                 sgn=-1.0f;
02813                 rni=1.0f/(float)n;
02814                 j=1;
02815                 for (i=1; i<=n; i++) {
02816                         br(j)=br(j)*rni;
02817                         bi(j)=bi(j)*rni;
02818                         j=j+k;
02819                 }
02820         }
02821 L12:
02822    b6=b6/2;
02823    b5=b6;
02824    b4=2*b6;
02825    b56=b5-b6;
02826 L14:
02827    tr1=br(b5+1);
02828    ti1=bi(b5+1);
02829 
02830    tr2=br(b56+1);
02831    ti2=bi(b56+1);
02832 
02833    br(b5+1)=tr2-tr1;
02834    bi(b5+1)=ti2-ti1;
02835    br(b56+1)=tr1+tr2;
02836    bi(b56+1)=ti1+ti2;
02837 
02838    b5=b5+b4;
02839    b56=b5-b6;
02840    if ( b5 <= b3 )  goto  L14;
02841    if ( b6 == b7 )  goto  L20;
02842 
02843    b4=b7;
02844    cc=2.0f*pow(tab1(l),2);
02845    c=1.0f-cc;
02846    l++;
02847    ss=sgn*tab1(l);
02848    s=ss;
02849 L16:
02850    b5=b6+b4;
02851    b4=2*b6;
02852    b56=b5-b6;
02853 L18:
02854    tr1=br(b5+1);
02855    ti1=bi(b5+1);
02856    tr2=br(b56+1);
02857    ti2=bi(b56+1);
02858    br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1);
02859    bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1);
02860    br(b56+1)=tr1+tr2;
02861    bi(b56+1)=ti1+ti2;
02862 
02863    b5=b5+b4;
02864    b56=b5-b6;
02865    if(b5 <= b3)  goto L18;
02866    b4=b5-b6;
02867    b5=b4-b3;
02868    c=-c;
02869    b4=b6-b5;
02870    if(b5 < b4)  goto  L16;
02871    b4=b4+b7;
02872    if(b4 >= b5) goto  L12;
02873 
02874    t=c-cc*c-ss*s;
02875    s=s+ss*c-cc*s;
02876    c=t;
02877    goto  L16;
02878 L20:
02879    ix0=b3/2;
02880    b3=b3-b7;
02881    b4=0;
02882    b5=0;
02883    b6=ix0;
02884    ix1=0;
02885    if ( b6 == b7) goto EXIT;
02886 L22:
02887    b4=b3-b4;
02888    b5=b3-b5;
02889    x2=br(b4+1);
02890    x3=br(b5+1);
02891    x4=bi(b4+1);
02892    x5=bi(b5+1);
02893    br(b4+1)=x3;
02894    br(b5+1)=x2;
02895    bi(b4+1)=x5;
02896    bi(b5+1)=x4;
02897    if (b6 < b4) goto  L22;
02898 L24:
02899    b4=b4+b7;
02900    b5=b6+b5;
02901    x2=br(b4+1);
02902    x3=br(b5+1);
02903    x4=bi(b4+1);
02904    x5=bi(b5+1);
02905    br(b4+1)=x3;
02906    br(b5+1)=x2;
02907    bi(b4+1)=x5;
02908    bi(b5+1)=x4;
02909    ix0=b6;
02910 L26:
02911    ix0=ix0/2;
02912    ix1=ix1-ix0;
02913    if(ix1 >= 0)  goto  L26;
02914 
02915    ix0=2*ix0;
02916    b4=b4+b7;
02917    ix1=ix1+ix0;
02918    b5=ix1;
02919    if (b5 >= b4)  goto  L22;
02920    if (b4 < b6)   goto  L24;
02921 EXIT:
02922    status = 0;
02923 }

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

Definition at line 3007 of file util_sparx.cpp.

References abs, fftc_d(), t, tab1, and xcmplx.

Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ms_delta(), Crosrng_msg(), Crosrng_msg_m(), Crosrng_msg_s(), Crosrng_ns(), Crosrng_psi_0_180(), and Crosrng_sm_psi().

03008 {
03009         // double precision  x(2,1)
03010         int    i1, i2,  nu, inv, nu1, n, isub, n2, i;
03011         double tr1,tr2,ti1,ti2,tr,ti;
03012         double cc,c,ss,s,t;
03013         const double tab1[] = {
03014                 9.58737990959775e-5,
03015                 1.91747597310703e-4,
03016                 3.83495187571395e-4,
03017                 7.66990318742704e-4,
03018                 1.53398018628476e-3,
03019                 3.06795676296598e-3,
03020                 6.13588464915449e-3,
03021                 1.22715382857199e-2,
03022                 2.45412285229123e-2,
03023                 4.90676743274181e-2,
03024                 9.80171403295604e-2,
03025                 1.95090322016128e-1,
03026                 3.82683432365090e-1,
03027                 7.07106781186546e-1,
03028                 1.00000000000000,
03029         };
03030 
03031         nu=abs(nv);
03032         inv=nv/nu;
03033         nu1=nu-1;
03034         n=(int)pow(2.0f,nu1);
03035         isub=16-nu1;
03036         ss=-tab1(isub);
03037         cc=-2.0*pow(tab1(isub-1),2);
03038         c=1.0f;
03039         s=0.0f;
03040         n2=n/2;
03041 
03042         if ( inv > 0 ) {
03043                 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,2);
03044                 tr=xcmplx(1,1);
03045                 ti=xcmplx(2,1);
03046                 xcmplx(1,1)=tr+ti;
03047                 xcmplx(2,1)=tr-ti;
03048                 for (i=1;i<=n2;i++) {
03049                         i1=i+1;
03050                         i2=n-i+1;
03051                         tr1=xcmplx(1,i1);
03052                         tr2=xcmplx(1,i2);
03053                         ti1=xcmplx(2,i1);
03054                         ti2=xcmplx(2,i2);
03055                         t=(cc*c-ss*s)+c;
03056                         s=(cc*s+ss*c)+s;
03057                         c=t;
03058                         xcmplx(1,i1)=0.5*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s);
03059                         xcmplx(1,i2)=0.5*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s);
03060                         xcmplx(2,i1)=0.5*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c);
03061                         xcmplx(2,i2)=0.5*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c);
03062                 }
03063         } else {
03064                 tr=xcmplx(1,1);
03065                 ti=xcmplx(2,1);
03066                 xcmplx(1,1)=0.5*(tr+ti);
03067                 xcmplx(2,1)=0.5*(tr-ti);
03068                 for (i=1; i<=n2; i++) {
03069                         i1=i+1;
03070                         i2=n-i+1;
03071                         tr1=xcmplx(1,i1);
03072                         tr2=xcmplx(1,i2);
03073                         ti1=xcmplx(2,i1);
03074                         ti2=xcmplx(2,i2);
03075                         t=(cc*c-ss*s)+c;
03076                         s=(cc*s+ss*c)+s;
03077                         c=t;
03078                         xcmplx(1,i1)=0.5*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c);
03079                         xcmplx(1,i2)=0.5*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c);
03080                         xcmplx(2,i1)=0.5*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s);
03081                         xcmplx(2,i2)=0.5*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s);
03082                 }
03083                 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,-2);
03084         }
03085 }

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

Definition at line 2925 of file util_sparx.cpp.

References abs, fftc_q(), t, tab1, and xcmplx.

Referenced by Crosrng_msg_vec(), Frngs(), and Frngs_inv().

02926 {
02927    // dimension xcmplx(2,1); xcmplx(1,i) --- real, xcmplx(2,i) --- imaginary
02928 
02929         int nu, inv, nu1, n, isub, n2, i1, i2, i;
02930         float ss, cc, c, s, tr, ti, tr1, tr2, ti1, ti2, t;
02931 
02932         const float tab1[] = {
02933                 9.58737990959775e-5f,
02934                 1.91747597310703e-4f,
02935                 3.83495187571395e-4f,
02936                 7.66990318742704e-4f,
02937                 1.53398018628476e-3f,
02938                 3.06795676296598e-3f,
02939                 6.13588464915449e-3f,
02940                 1.22715382857199e-2f,
02941                 2.45412285229123e-2f,
02942                 4.90676743274181e-2f,
02943                 9.80171403295604e-2f,
02944                 1.95090322016128e-1f,
02945                 3.82683432365090e-1f,
02946                 7.07106781186546e-1f,
02947                 1.00000000000000f,
02948         };
02949 
02950         nu=abs(nv);
02951         inv=nv/nu;
02952         nu1=nu-1;
02953         n=(int)pow(2.f,nu1);
02954         isub=16-nu1;
02955 
02956         ss=-tab1(isub);
02957         cc=-2.0f*pow(tab1(isub-1),2.f);
02958         c=1.0f;
02959         s=0.0f;
02960         n2=n/2;
02961         if ( inv > 0) {
02962                 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,2);
02963                 tr=xcmplx(1,1);
02964                 ti=xcmplx(2,1);
02965                 xcmplx(1,1)=tr+ti;
02966                 xcmplx(2,1)=tr-ti;
02967                 for (i=1;i<=n2;i++) {
02968                         i1=i+1;
02969                         i2=n-i+1;
02970                         tr1=xcmplx(1,i1);
02971                         tr2=xcmplx(1,i2);
02972                         ti1=xcmplx(2,i1);
02973                         ti2=xcmplx(2,i2);
02974                         t=(cc*c-ss*s)+c;
02975                         s=(cc*s+ss*c)+s;
02976                         c=t;
02977                         xcmplx(1,i1)=0.5f*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s);
02978                         xcmplx(1,i2)=0.5f*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s);
02979                         xcmplx(2,i1)=0.5f*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c);
02980                         xcmplx(2,i2)=0.5f*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c);
02981                 }
02982         } else {
02983                 tr=xcmplx(1,1);
02984                 ti=xcmplx(2,1);
02985                 xcmplx(1,1)=0.5f*(tr+ti);
02986                 xcmplx(2,1)=0.5f*(tr-ti);
02987                 for (i=1; i<=n2; i++) {
02988                         i1=i+1;
02989                         i2=n-i+1;
02990                         tr1=xcmplx(1,i1);
02991                         tr2=xcmplx(1,i2);
02992                         ti1=xcmplx(2,i1);
02993                         ti2=xcmplx(2,i2);
02994                         t=(cc*c-ss*s)+c;
02995                         s=(cc*s+ss*c)+s;
02996                         c=t;
02997                         xcmplx(1,i1)=0.5f*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c);
02998                         xcmplx(1,i2)=0.5f*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c);
02999                         xcmplx(2,i1)=0.5f*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s);
03000                         xcmplx(2,i2)=0.5f*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s);
03001                 }
03002                 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,-2);
03003         }
03004 }

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

lock a file.

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

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 812 of file util.cpp.

References Assert, max, and NullPointerException.

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

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

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

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

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 836 of file util.cpp.

References Assert, max, min, and NullPointerException.

00839 {
00840         Assert(nitems > 0);
00841 
00842         if (!data || !max_val || !min_val || !max_index || !min_index) {
00843                 throw NullPointerException("data/max_val/min_val/max_index/min_index");
00844         }
00845         float max = -FLT_MAX;
00846         float min = FLT_MAX;
00847         int max_i = 0;
00848         int min_i = 0;
00849 
00850         for (size_t i = 0; i < nitems; i++) {
00851                 if (data[i] > max) {
00852                         max = data[i];
00853                         max_i = (int)i;
00854                 }
00855                 if (data[i] < min) {
00856                         min = data[i];
00857                         min_i = (int)i;
00858                 }
00859         }
00860 
00861         *max_val = max;
00862         *min_val = min;
00863 
00864         if (min_index) {
00865                 *min_index = min_i;
00866         }
00867 
00868         if (max_index) {
00869                 *max_index = max_i;
00870         }
00871 
00872 }

int Util::findTopLargest int *  argParts,
int *  Indices,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int *  matchlist,
int  max_num_matches,
int *  costlist,
int  n_guesses
[static]
 

find max_num_matches feasible matches (if possible) which has weight gt T, and weight gteq weight of all other feasible matches.

return the results in the pre-allocated arrays matchlist and costlist. Each match is a sequence (stored in a 1D array) of nParts numbers, where the i-th element in the sequence is the original index of the class from the i-th partition. Those classes in argParts whose dummy variable is 1 are the classes which are not yet used (i.e., those which can be used to construct the feasible matches) returns the number of matches found. it's less than the number request if there aren't that many that's over the threshold

Definition at line 20047 of file util_sparx.cpp.

References generatesubmax(), and search2().

20047                                                                                                                                                                  {
20048         int guess;
20049         int* curmax = new int[nParts+1]; // first element is the max weight and the subsequent elements is the match with the weight.
20050         int newT=T;
20051         int num_found=0;
20052 
20053         for(int i=0; i < max_num_matches; i++){
20054                 guess = Util::generatesubmax(argParts, Indices,dimClasses,nParts, K, T,  n_guesses);
20055 
20056                 if (T < guess) newT = guess -1;
20057                 // find the feasible match with the largest weight and put results in curmax
20058                 Util::search2(argParts, Indices,dimClasses,nParts, K, newT,curmax);
20059                 if (*curmax <= T){
20060                         max_num_matches=i;
20061                         break;
20062                 }
20063                 else {
20064                         *(costlist+i) = *curmax;
20065 
20066                         for (int j=0; j<nParts; j++){
20067                                 *(matchlist+i*nParts+j) = *(curmax+1+j);
20068                                 *(argParts + Indices[j*K+*(curmax+1+j)] + 1) = -3;// mark the classes in curmax as unavailable using -3 (remember to change it back)
20069 
20070                         }
20071                         num_found = num_found+1;
20072                 }
20073 
20074         }
20075 
20076 
20077         delete[] curmax;
20078         // go through the selected classes (in matchlist) and reset to 1
20079 
20080         for (int i=0 ; i < max_num_matches; i++){
20081                 for (int j = 0; j < nParts; j++){
20082                         *(argParts + Indices[j*K+*(matchlist+i*nParts +j)] + 1) = 1;
20083                 }
20084 
20085         }
20086 
20087 
20088         return num_found;
20089 }

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

Definition at line 7710 of file util_sparx.cpp.

References ENTERFUNC, and EXITFUNC.

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

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

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

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

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

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

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

Definition at line 3108 of file util_sparx.cpp.

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

03108                                                    {
03109         int nring = numr.size()/3;
03110         float *circ = circp->get_data();
03111         int i, l;
03112         for (i=1; i<=nring;i++) {
03113 
03114 #ifdef _WIN32
03115                 l = (int)( log((float)numr(3,i))/log(2.0f) );
03116 #else
03117                 l=(int)(log2(numr(3,i)));
03118 #endif  //_WIN32
03119 
03120                 fftr_q(&circ(numr(2,i)),-l);
03121         }
03122 }

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

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

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

Definition at line 20336 of file util_sparx.cpp.

References b, and k_means_cont_table_().

20336                                                                                                              {
20337         int guess=0;
20338 
20339         int* perm = new int[nParts];
20340         for(int i=0; i<nParts; i++) perm[i]=i;
20341 
20342         // some temporary variables
20343         int* intx(0);
20344         int* intx_next(0);
20345         int nintx;
20346         int nintxmax=0;
20347         int class_max = 0, class_max_next = 0;
20348         int intx_size = 0, part, part_next;
20349         int ipold,indsw;
20350 
20351         for(int i=0; i< n_guesses; i++){
20352                 // shuffle perm array
20353                 for(int ip = 0; ip<nParts; ip++){
20354                         indsw = (rand())%nParts;
20355                         // swap ip(th) element with the (indsw)th element
20356                         ipold = perm[ip];
20357                         perm[ip]=perm[indsw];
20358                         perm[indsw]=ipold;
20359                 }
20360 
20361 
20362                 // find the two classes in partitions perm[0] and perm[1] that yield the largest intersection
20363                 part=*perm;
20364                 part_next=*(perm+1);
20365                 for (int a=0; a < K; a++)
20366                 {
20367                         if (*(argParts + Indices[part*K+a] + 1) < 1) continue;
20368                         for (int b=0; b < K; b++)
20369                         {
20370                                 if (*(argParts + Indices[part_next*K + b] + 1) < 1) continue;
20371                                 nintx = Util::k_means_cont_table_(argParts + Indices[part*K+a]+2,argParts + Indices[part_next*K + b]+2, intx, *(dimClasses + part*K+a)-2,  *(dimClasses + part_next*K + b)-2,0);
20372                                 if (nintx <= nintxmax) continue;
20373                                 nintxmax = nintx;
20374                                 class_max = a;
20375                                 class_max_next = b;
20376                         }
20377                 }
20378 
20379                 // no more....
20380                 if (nintxmax < 1) {continue;}
20381 
20382                 if (nParts > 2){
20383                         intx = new int[nintxmax];
20384                         intx_size = nintxmax;
20385                         Util::k_means_cont_table_(argParts + Indices[part*K+class_max]+2,argParts + Indices[part_next*K + class_max_next]+2, intx, *(dimClasses + part*K+class_max)-2, *(dimClasses+part_next*K+class_max_next)-2,1); // get intx
20386                 }
20387 
20388                 // for each subsequent partition perm[i], i>=2, find the partition that yields the largest weight with the current intx
20389                 for(int j = 2; j < nParts; j++){
20390                         part = *(perm+j);
20391                         nintxmax=0;
20392                         for(int a = 0; a < K; a++){
20393                                 if (*(argParts + Indices[part*K+a] + 1) < 1) continue; // skip inactive classes
20394                                 nintx =  Util::k_means_cont_table_(intx, argParts + Indices[part*K + a]+2, intx_next, intx_size,  (*(dimClasses + part*K+a))-2,0);
20395                                 if (nintx <= nintxmax) continue;
20396                                 nintxmax = nintx;
20397                                 class_max = a;
20398                         }
20399 
20400                         // no more stuff....
20401                         if (nintxmax < 1) {
20402 
20403                                 delete[] intx;
20404                                 break;
20405                         }
20406 
20407 
20408                         intx_next = new int[nintxmax];
20409                         Util::k_means_cont_table_(intx, argParts + Indices[part*K + class_max]+2, intx_next, intx_size,  *(dimClasses + part*K+class_max)-2,1);
20410                         delete[] intx;
20411                         intx = intx_next;
20412                         intx_size = nintxmax;
20413                         if (j==nParts - 1) delete[] intx_next;
20414 
20415                 }
20416 
20417                 if (nintxmax > guess) guess = nintxmax;
20418 
20419         }
20420         delete[] perm;
20421         return guess;
20422 }

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

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

19104 {
19105         int nx = mg->get_xsize();
19106         int ny = mg->get_ysize();
19107         int nz = mg->get_zsize();
19108 
19109         EMData* visited = new EMData();
19110         visited->set_size( nx, ny, nz );
19111         visited->to_zero();
19112         int grpid = 0;
19113         int maxgrp = 0;
19114         int maxsize = 0;
19115         for( int iz=0; iz < nz; ++iz ) {
19116                 for( int iy=0; iy < ny; ++iy ) {
19117                         for( int ix=0; ix < nx; ++ix ) {
19118                                 if( (*mg)(ix, iy, iz)==0.0 ) continue;
19119 
19120                                 if( (*visited)(ix, iy, iz) > 0.0 ) {
19121                                         // visited before, must be in other group.
19122                                         continue;
19123                                 }
19124 
19125                                 grpid++;
19126                                 int grpsize = find_group( ix, iy, iz, grpid, mg, visited );
19127                                 if( grpsize > maxsize ) {
19128                                         maxsize = grpsize;
19129                                         maxgrp = grpid;
19130                                 }
19131                         }
19132                 }
19133         }
19134 
19135         Assert( maxgrp > 0 );
19136 
19137         int npoint = 0;
19138         EMData* result = new EMData();
19139         result->set_size( nx, ny, nz );
19140         result->to_zero();
19141 
19142         for( int iz=0; iz < nz; ++iz ) {
19143                 for( int iy=0; iy < ny; ++iy ) {
19144                         for( int ix=0; ix < nx; ++ix ) {
19145                                 if( (*visited)(ix, iy, iz)==maxgrp ) {
19146                                         (*result)(ix,iy,iz) = 1.0;
19147                                         npoint++;
19148                                 }
19149                         }
19150                 }
19151         }
19152 
19153         Assert( npoint==maxsize );
19154         delete visited;
19155         return result;
19156 
19157 }

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(), main(), 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 806 of file util.cpp.

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

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

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

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

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

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 1816 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 1798 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 1787 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 1767 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 1748 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 1737 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 1721 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 1710 of file util.h.

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

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

Definition at line 775 of file util_sparx.cpp.

References EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), restrict1(), and round().

Referenced by Polar2Dmi().

00775                                                                                                                              {
00776         int K = kb.get_window_size();
00777         int kbmin = -K/2;
00778         int kbmax = -kbmin;
00779         int kbc = kbmax+1;
00780 
00781         float pixel =0.0f;
00782         float w=0.0f;
00783 
00784         delx = restrict1(delx, nx);
00785         int inxold = int(round(delx));
00786         if ( ny < 2 ) {  //1D
00787                 float tablex1 = kb.i0win_tab(delx-inxold+3);
00788                 float tablex2 = kb.i0win_tab(delx-inxold+2);
00789                 float tablex3 = kb.i0win_tab(delx-inxold+1);
00790                 float tablex4 = kb.i0win_tab(delx-inxold);
00791                 float tablex5 = kb.i0win_tab(delx-inxold-1);
00792                 float tablex6 = kb.i0win_tab(delx-inxold-2);
00793                 float tablex7 = kb.i0win_tab(delx-inxold-3);
00794 
00795                 int x1, x2, x3, x4, x5, x6, x7;
00796 
00797                 if ( inxold <= kbc || inxold >=nx-kbc-2 )  {
00798                         x1 = (inxold-3+nx)%nx;
00799                         x2 = (inxold-2+nx)%nx;
00800                         x3 = (inxold-1+nx)%nx;
00801                         x4 = (inxold  +nx)%nx;
00802                         x5 = (inxold+1+nx)%nx;
00803                         x6 = (inxold+2+nx)%nx;
00804                         x7 = (inxold+3+nx)%nx;
00805                 } else {
00806                         x1 = inxold-3;
00807                         x2 = inxold-2;
00808                         x3 = inxold-1;
00809                         x4 = inxold;
00810                         x5 = inxold+1;
00811                         x6 = inxold+2;
00812                         x7 = inxold+3;
00813                 }
00814 
00815                 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 +
00816                         data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 +
00817                         data[x7]*tablex7 ;
00818 
00819                 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7;
00820         } else if ( nz < 2 ) {  // 2D
00821                 dely = restrict1(dely, ny);
00822                 int inyold = int(round(dely));
00823                 float tablex1 = kb.i0win_tab(delx-inxold+3);
00824                 float tablex2 = kb.i0win_tab(delx-inxold+2);
00825                 float tablex3 = kb.i0win_tab(delx-inxold+1);
00826                 float tablex4 = kb.i0win_tab(delx-inxold);
00827                 float tablex5 = kb.i0win_tab(delx-inxold-1);
00828                 float tablex6 = kb.i0win_tab(delx-inxold-2);
00829                 float tablex7 = kb.i0win_tab(delx-inxold-3);
00830 
00831                 float tabley1 = kb.i0win_tab(dely-inyold+3);
00832                 float tabley2 = kb.i0win_tab(dely-inyold+2);
00833                 float tabley3 = kb.i0win_tab(dely-inyold+1);
00834                 float tabley4 = kb.i0win_tab(dely-inyold);
00835                 float tabley5 = kb.i0win_tab(dely-inyold-1);
00836                 float tabley6 = kb.i0win_tab(dely-inyold-2);
00837                 float tabley7 = kb.i0win_tab(dely-inyold-3);
00838 
00839                 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7;
00840 
00841                 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 )  {
00842                         x1 = (inxold-3+nx)%nx;
00843                         x2 = (inxold-2+nx)%nx;
00844                         x3 = (inxold-1+nx)%nx;
00845                         x4 = (inxold  +nx)%nx;
00846                         x5 = (inxold+1+nx)%nx;
00847                         x6 = (inxold+2+nx)%nx;
00848                         x7 = (inxold+3+nx)%nx;
00849 
00850                         y1 = ((inyold-3+ny)%ny)*nx;
00851                         y2 = ((inyold-2+ny)%ny)*nx;
00852                         y3 = ((inyold-1+ny)%ny)*nx;
00853                         y4 = ((inyold  +ny)%ny)*nx;
00854                         y5 = ((inyold+1+ny)%ny)*nx;
00855                         y6 = ((inyold+2+ny)%ny)*nx;
00856                         y7 = ((inyold+3+ny)%ny)*nx;
00857                 } else {
00858                         x1 = inxold-3;
00859                         x2 = inxold-2;
00860                         x3 = inxold-1;
00861                         x4 = inxold;
00862                         x5 = inxold+1;
00863                         x6 = inxold+2;
00864                         x7 = inxold+3;
00865 
00866                         y1 = (inyold-3)*nx;
00867                         y2 = (inyold-2)*nx;
00868                         y3 = (inyold-1)*nx;
00869                         y4 = inyold*nx;
00870                         y5 = (inyold+1)*nx;
00871                         y6 = (inyold+2)*nx;
00872                         y7 = (inyold+3)*nx;
00873                 }
00874 
00875                 pixel    = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 +
00876                              data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 +
00877                              data[x7+y1]*tablex7 ) * tabley1 +
00878                            ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 +
00879                              data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 +
00880                              data[x7+y2]*tablex7 ) * tabley2 +
00881                            ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 +
00882                              data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 +
00883                              data[x7+y3]*tablex7 ) * tabley3 +
00884                            ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 +
00885                              data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 +
00886                              data[x7+y4]*tablex7 ) * tabley4 +
00887                            ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 +
00888                              data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 +
00889                              data[x7+y5]*tablex7 ) * tabley5 +
00890                            ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 +
00891                              data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 +
00892                              data[x7+y6]*tablex7 ) * tabley6 +
00893                            ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 +
00894                              data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 +
00895                              data[x7+y7]*tablex7 ) * tabley7;
00896 
00897                 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) *
00898                     (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7);
00899         } else {  //  3D
00900                 dely = restrict1(dely, ny);
00901                 int inyold = int(Util::round(dely));
00902                 delz = restrict1(delz, nz);
00903                 int inzold = int(Util::round(delz));
00904 
00905                 float tablex1 = kb.i0win_tab(delx-inxold+3);
00906                 float tablex2 = kb.i0win_tab(delx-inxold+2);
00907                 float tablex3 = kb.i0win_tab(delx-inxold+1);
00908                 float tablex4 = kb.i0win_tab(delx-inxold);
00909                 float tablex5 = kb.i0win_tab(delx-inxold-1);
00910                 float tablex6 = kb.i0win_tab(delx-inxold-2);
00911                 float tablex7 = kb.i0win_tab(delx-inxold-3);
00912 
00913                 float tabley1 = kb.i0win_tab(dely-inyold+3);
00914                 float tabley2 = kb.i0win_tab(dely-inyold+2);
00915                 float tabley3 = kb.i0win_tab(dely-inyold+1);
00916                 float tabley4 = kb.i0win_tab(dely-inyold);
00917                 float tabley5 = kb.i0win_tab(dely-inyold-1);
00918                 float tabley6 = kb.i0win_tab(dely-inyold-2);
00919                 float tabley7 = kb.i0win_tab(dely-inyold-3);
00920 
00921                 float tablez1 = kb.i0win_tab(delz-inzold+3);
00922                 float tablez2 = kb.i0win_tab(delz-inzold+2);
00923                 float tablez3 = kb.i0win_tab(delz-inzold+1);
00924                 float tablez4 = kb.i0win_tab(delz-inzold);
00925                 float tablez5 = kb.i0win_tab(delz-inzold-1);
00926                 float tablez6 = kb.i0win_tab(delz-inzold-2);
00927                 float tablez7 = kb.i0win_tab(delz-inzold-3);
00928 
00929                 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7;
00930 
00931                 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 )  {
00932                         x1 = (inxold-3+nx)%nx;
00933                         x2 = (inxold-2+nx)%nx;
00934                         x3 = (inxold-1+nx)%nx;
00935                         x4 = (inxold  +nx)%nx;
00936                         x5 = (inxold+1+nx)%nx;
00937                         x6 = (inxold+2+nx)%nx;
00938                         x7 = (inxold+3+nx)%nx;
00939 
00940                         y1 = ((inyold-3+ny)%ny)*nx;
00941                         y2 = ((inyold-2+ny)%ny)*nx;
00942                         y3 = ((inyold-1+ny)%ny)*nx;
00943                         y4 = ((inyold  +ny)%ny)*nx;
00944                         y5 = ((inyold+1+ny)%ny)*nx;
00945                         y6 = ((inyold+2+ny)%ny)*nx;
00946                         y7 = ((inyold+3+ny)%ny)*nx;
00947 
00948                         z1 = ((inzold-3+nz)%nz)*nx*ny;
00949                         z2 = ((inzold-2+nz)%nz)*nx*ny;
00950                         z3 = ((inzold-1+nz)%nz)*nx*ny;
00951                         z4 = ((inzold  +nz)%nz)*nx*ny;
00952                         z5 = ((inzold+1+nz)%nz)*nx*ny;
00953                         z6 = ((inzold+2+nz)%nz)*nx*ny;
00954                         z7 = ((inzold+3+nz)%nz)*nx*ny;
00955                 } else {
00956                         x1 = inxold-3;
00957                         x2 = inxold-2;
00958                         x3 = inxold-1;
00959                         x4 = inxold;
00960                         x5 = inxold+1;
00961                         x6 = inxold+2;
00962                         x7 = inxold+3;
00963 
00964                         y1 = (inyold-3)*nx;
00965                         y2 = (inyold-2)*nx;
00966                         y3 = (inyold-1)*nx;
00967                         y4 = inyold*nx;
00968                         y5 = (inyold+1)*nx;
00969                         y6 = (inyold+2)*nx;
00970                         y7 = (inyold+3)*nx;
00971 
00972                         z1 = (inzold-3)*nx*ny;
00973                         z2 = (inzold-2)*nx*ny;
00974                         z3 = (inzold-1)*nx*ny;
00975                         z4 = inzold*nx*ny;
00976                         z5 = (inzold+1)*nx*ny;
00977                         z6 = (inzold+2)*nx*ny;
00978                         z7 = (inzold+3)*nx*ny;
00979                 }
00980 
00981                 pixel  = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 +
00982                              data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 +
00983                              data[x7+y1+z1]*tablex7 ) * tabley1 +
00984                            ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 +
00985                              data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 +
00986                              data[x7+y2+z1]*tablex7 ) * tabley2 +
00987                            ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 +
00988                              data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 +
00989                              data[x7+y3+z1]*tablex7 ) * tabley3 +
00990                            ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 +
00991                              data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 +
00992                              data[x7+y4+z1]*tablex7 ) * tabley4 +
00993                            ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 +
00994                              data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 +
00995                              data[x7+y5+z1]*tablex7 ) * tabley5 +
00996                            ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 +
00997                              data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 +
00998                              data[x7+y6+z1]*tablex7 ) * tabley6 +
00999                            ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 +
01000                              data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 +
01001                              data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 +
01002                          ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 +
01003                              data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 +
01004                              data[x7+y1+z2]*tablex7 ) * tabley1 +
01005                            ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 +
01006                              data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 +
01007                              data[x7+y2+z2]*tablex7 ) * tabley2 +
01008                            ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 +
01009                              data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 +
01010                              data[x7+y3+z2]*tablex7 ) * tabley3 +
01011                            ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 +
01012                              data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 +
01013                              data[x7+y4+z2]*tablex7 ) * tabley4 +
01014                            ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 +
01015                              data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 +
01016                              data[x7+y5+z2]*tablex7 ) * tabley5 +
01017                            ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 +
01018                              data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 +
01019                              data[x7+y6+z2]*tablex7 ) * tabley6 +
01020                            ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 +
01021                              data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 +
01022                              data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 +
01023                          ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 +
01024                              data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 +
01025                              data[x7+y1+z3]*tablex7 ) * tabley1 +
01026                            ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 +
01027                              data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 +
01028                              data[x7+y2+z3]*tablex7 ) * tabley2 +
01029                            ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 +
01030                              data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 +
01031                              data[x7+y3+z3]*tablex7 ) * tabley3 +
01032                            ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 +
01033                              data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 +
01034                              data[x7+y4+z3]*tablex7 ) * tabley4 +
01035                            ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 +
01036                              data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 +
01037                              data[x7+y5+z3]*tablex7 ) * tabley5 +
01038                            ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 +
01039                              data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 +
01040                              data[x7+y6+z3]*tablex7 ) * tabley6 +
01041                            ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 +
01042                              data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 +
01043                              data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 +
01044                          ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 +
01045                              data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 +
01046                              data[x7+y1+z4]*tablex7 ) * tabley1 +
01047                            ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 +
01048                              data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 +
01049                              data[x7+y2+z4]*tablex7 ) * tabley2 +
01050                            ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 +
01051                              data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 +
01052                              data[x7+y3+z4]*tablex7 ) * tabley3 +
01053                            ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 +
01054                              data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 +
01055                              data[x7+y4+z4]*tablex7 ) * tabley4 +
01056                            ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 +
01057                              data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 +
01058                              data[x7+y5+z4]*tablex7 ) * tabley5 +
01059                            ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 +
01060                              data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 +
01061                              data[x7+y6+z4]*tablex7 ) * tabley6 +
01062                            ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 +
01063                              data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 +
01064                              data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 +
01065                          ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 +
01066                              data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 +
01067                              data[x7+y1+z5]*tablex7 ) * tabley1 +
01068                            ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 +
01069                              data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 +
01070                              data[x7+y2+z5]*tablex7 ) * tabley2 +
01071                            ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 +
01072                              data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 +
01073                              data[x7+y3+z5]*tablex7 ) * tabley3 +
01074                            ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 +
01075                              data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 +
01076                              data[x7+y4+z5]*tablex7 ) * tabley4 +
01077                            ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 +
01078                              data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 +
01079                              data[x7+y5+z5]*tablex7 ) * tabley5 +
01080                            ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 +
01081                              data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 +
01082                              data[x7+y6+z5]*tablex7 ) * tabley6 +
01083                            ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 +
01084                              data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 +
01085                              data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 +
01086                          ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 +
01087                              data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 +
01088                              data[x7+y1+z6]*tablex7 ) * tabley1 +
01089                            ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 +
01090                              data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 +
01091                              data[x7+y2+z6]*tablex7 ) * tabley2 +
01092                            ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 +
01093                              data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 +
01094                              data[x7+y3+z6]*tablex7 ) * tabley3 +
01095                            ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 +
01096                              data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 +
01097                              data[x7+y4+z6]*tablex7 ) * tabley4 +
01098                            ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 +
01099                              data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 +
01100                              data[x7+y5+z6]*tablex7 ) * tabley5 +
01101                            ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 +
01102                              data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 +
01103                              data[x7+y6+z6]*tablex7 ) * tabley6 +
01104                            ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 +
01105                              data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 +
01106                              data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 +
01107                          ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 +
01108                              data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 +
01109                              data[x7+y1+z7]*tablex7 ) * tabley1 +
01110                            ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 +
01111                              data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 +
01112                              data[x7+y2+z7]*tablex7 ) * tabley2 +
01113                            ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 +
01114                              data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 +
01115                              data[x7+y3+z7]*tablex7 ) * tabley3 +
01116                            ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 +
01117                              data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 +
01118                              data[x7+y4+z7]*tablex7 ) * tabley4 +
01119                            ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 +
01120                              data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 +
01121                              data[x7+y5+z7]*tablex7 ) * tabley5 +
01122                            ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 +
01123                              data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 +
01124                              data[x7+y6+z7]*tablex7 ) * tabley6 +
01125                            ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 +
01126                              data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 +
01127                              data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7;
01128 
01129                 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) *
01130                     (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) *
01131                     (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7);
01132         }
01133         return pixel/w;
01134 }

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

Definition at line 1136 of file util_sparx.cpp.

References EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), restrict1(), and round().

01136                                                                                                                                                             {
01137         int K = kb.get_window_size();
01138         int kbmin = -K/2;
01139         int kbmax = -kbmin;
01140         int kbc = kbmax+1;
01141 
01142         float pixel =0.0f;
01143         float w=0.0f;
01144 
01145     float argdelx = delx; // adding this for 2D case where the wrap around is not done circulantly using restrict1.
01146         delx = restrict1(delx, nx);
01147         int inxold = int(round(delx));
01148         if ( ny < 2 ) {  //1D
01149                 float tablex1 = kb.i0win_tab(delx-inxold+3);
01150                 float tablex2 = kb.i0win_tab(delx-inxold+2);
01151                 float tablex3 = kb.i0win_tab(delx-inxold+1);
01152                 float tablex4 = kb.i0win_tab(delx-inxold);
01153                 float tablex5 = kb.i0win_tab(delx-inxold-1);
01154                 float tablex6 = kb.i0win_tab(delx-inxold-2);
01155                 float tablex7 = kb.i0win_tab(delx-inxold-3);
01156 
01157                 int x1, x2, x3, x4, x5, x6, x7;
01158 
01159                 if ( inxold <= kbc || inxold >=nx-kbc-2 )  {
01160                         x1 = (inxold-3+nx)%nx;
01161                         x2 = (inxold-2+nx)%nx;
01162                         x3 = (inxold-1+nx)%nx;
01163                         x4 = (inxold  +nx)%nx;
01164                         x5 = (inxold+1+nx)%nx;
01165                         x6 = (inxold+2+nx)%nx;
01166                         x7 = (inxold+3+nx)%nx;
01167                 } else {
01168                         x1 = inxold-3;
01169                         x2 = inxold-2;
01170                         x3 = inxold-1;
01171                         x4 = inxold;
01172                         x5 = inxold+1;
01173                         x6 = inxold+2;
01174                         x7 = inxold+3;
01175                 }
01176 
01177                 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 +
01178                         data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 +
01179                         data[x7]*tablex7 ;
01180 
01181                 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7;
01182         } else if ( nz < 2 ) {  // 2D
01183 
01184                 delx = argdelx;
01185                 // the wrap around is not done circulantly for 2D case; if (argdelx, argdely) is not in the image, then make them (xnew, ynew) which is definitely in the image
01186                 if ((delx < 0.0f) || (delx >= (float) (nx)) || (dely < 0.0f) || (dely >= (float) (ny)) ){
01187                 delx = (float)xnew*2.0f;
01188                 dely = (float)ynew*2.0f;
01189                 }
01190 
01191                 int inxold = int(round(delx));
01192                 int inyold = int(round(dely));
01193 
01194                 float tablex1 = kb.i0win_tab(delx-inxold+3);
01195                 float tablex2 = kb.i0win_tab(delx-inxold+2);
01196                 float tablex3 = kb.i0win_tab(delx-inxold+1);
01197                 float tablex4 = kb.i0win_tab(delx-inxold);
01198                 float tablex5 = kb.i0win_tab(delx-inxold-1);
01199                 float tablex6 = kb.i0win_tab(delx-inxold-2);
01200                 float tablex7 = kb.i0win_tab(delx-inxold-3);
01201 
01202                 float tabley1 = kb.i0win_tab(dely-inyold+3);
01203                 float tabley2 = kb.i0win_tab(dely-inyold+2);
01204                 float tabley3 = kb.i0win_tab(dely-inyold+1);
01205                 float tabley4 = kb.i0win_tab(dely-inyold);
01206                 float tabley5 = kb.i0win_tab(dely-inyold-1);
01207                 float tabley6 = kb.i0win_tab(dely-inyold-2);
01208                 float tabley7 = kb.i0win_tab(dely-inyold-3);
01209 
01210                 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7;
01211 
01212                 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 )  {
01213                         x1 = (inxold-3+nx)%nx;
01214                         x2 = (inxold-2+nx)%nx;
01215                         x3 = (inxold-1+nx)%nx;
01216                         x4 = (inxold  +nx)%nx;
01217                         x5 = (inxold+1+nx)%nx;
01218                         x6 = (inxold+2+nx)%nx;
01219                         x7 = (inxold+3+nx)%nx;
01220 
01221                         y1 = ((inyold-3+ny)%ny)*nx;
01222                         y2 = ((inyold-2+ny)%ny)*nx;
01223                         y3 = ((inyold-1+ny)%ny)*nx;
01224                         y4 = ((inyold  +ny)%ny)*nx;
01225                         y5 = ((inyold+1+ny)%ny)*nx;
01226                         y6 = ((inyold+2+ny)%ny)*nx;
01227                         y7 = ((inyold+3+ny)%ny)*nx;
01228                 } else {
01229                         x1 = inxold-3;
01230                         x2 = inxold-2;
01231                         x3 = inxold-1;
01232                         x4 = inxold;
01233                         x5 = inxold+1;
01234                         x6 = inxold+2;
01235                         x7 = inxold+3;
01236 
01237                         y1 = (inyold-3)*nx;
01238                         y2 = (inyold-2)*nx;
01239                         y3 = (inyold-1)*nx;
01240                         y4 = inyold*nx;
01241                         y5 = (inyold+1)*nx;
01242                         y6 = (inyold+2)*nx;
01243                         y7 = (inyold+3)*nx;
01244                 }
01245 
01246                 pixel    = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 +
01247                              data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 +
01248                              data[x7+y1]*tablex7 ) * tabley1 +
01249                            ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 +
01250                              data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 +
01251                              data[x7+y2]*tablex7 ) * tabley2 +
01252                            ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 +
01253                              data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 +
01254                              data[x7+y3]*tablex7 ) * tabley3 +
01255                            ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 +
01256                              data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 +
01257                              data[x7+y4]*tablex7 ) * tabley4 +
01258                            ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 +
01259                              data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 +
01260                              data[x7+y5]*tablex7 ) * tabley5 +
01261                            ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 +
01262                              data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 +
01263                              data[x7+y6]*tablex7 ) * tabley6 +
01264                            ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 +
01265                              data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 +
01266                              data[x7+y7]*tablex7 ) * tabley7;
01267 
01268                 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) *
01269                     (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7);
01270         } else {  //  3D
01271                 dely = restrict1(dely, ny);
01272                 int inyold = int(Util::round(dely));
01273                 delz = restrict1(delz, nz);
01274                 int inzold = int(Util::round(delz));
01275 
01276                 float tablex1 = kb.i0win_tab(delx-inxold+3);
01277                 float tablex2 = kb.i0win_tab(delx-inxold+2);
01278                 float tablex3 = kb.i0win_tab(delx-inxold+1);
01279                 float tablex4 = kb.i0win_tab(delx-inxold);
01280                 float tablex5 = kb.i0win_tab(delx-inxold-1);
01281                 float tablex6 = kb.i0win_tab(delx-inxold-2);
01282                 float tablex7 = kb.i0win_tab(delx-inxold-3);
01283 
01284                 float tabley1 = kb.i0win_tab(dely-inyold+3);
01285                 float tabley2 = kb.i0win_tab(dely-inyold+2);
01286                 float tabley3 = kb.i0win_tab(dely-inyold+1);
01287                 float tabley4 = kb.i0win_tab(dely-inyold);
01288                 float tabley5 = kb.i0win_tab(dely-inyold-1);
01289                 float tabley6 = kb.i0win_tab(dely-inyold-2);
01290                 float tabley7 = kb.i0win_tab(dely-inyold-3);
01291 
01292                 float tablez1 = kb.i0win_tab(delz-inzold+3);
01293                 float tablez2 = kb.i0win_tab(delz-inzold+2);
01294                 float tablez3 = kb.i0win_tab(delz-inzold+1);
01295                 float tablez4 = kb.i0win_tab(delz-inzold);
01296                 float tablez5 = kb.i0win_tab(delz-inzold-1);
01297                 float tablez6 = kb.i0win_tab(delz-inzold-2);
01298                 float tablez7 = kb.i0win_tab(delz-inzold-3);
01299 
01300                 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7;
01301 
01302                 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 )  {
01303                         x1 = (inxold-3+nx)%nx;
01304                         x2 = (inxold-2+nx)%nx;
01305                         x3 = (inxold-1+nx)%nx;
01306                         x4 = (inxold  +nx)%nx;
01307                         x5 = (inxold+1+nx)%nx;
01308                         x6 = (inxold+2+nx)%nx;
01309                         x7 = (inxold+3+nx)%nx;
01310 
01311                         y1 = ((inyold-3+ny)%ny)*nx;
01312                         y2 = ((inyold-2+ny)%ny)*nx;
01313                         y3 = ((inyold-1+ny)%ny)*nx;
01314                         y4 = ((inyold  +ny)%ny)*nx;
01315                         y5 = ((inyold+1+ny)%ny)*nx;
01316                         y6 = ((inyold+2+ny)%ny)*nx;
01317                         y7 = ((inyold+3+ny)%ny)*nx;
01318 
01319                         z1 = ((inzold-3+nz)%nz)*nx*ny;
01320                         z2 = ((inzold-2+nz)%nz)*nx*ny;
01321                         z3 = ((inzold-1+nz)%nz)*nx*ny;
01322                         z4 = ((inzold  +nz)%nz)*nx*ny;
01323                         z5 = ((inzold+1+nz)%nz)*nx*ny;
01324                         z6 = ((inzold+2+nz)%nz)*nx*ny;
01325                         z7 = ((inzold+3+nz)%nz)*nx*ny;
01326                 } else {
01327                         x1 = inxold-3;
01328                         x2 = inxold-2;
01329                         x3 = inxold-1;
01330                         x4 = inxold;
01331                         x5 = inxold+1;
01332                         x6 = inxold+2;
01333                         x7 = inxold+3;
01334 
01335                         y1 = (inyold-3)*nx;
01336                         y2 = (inyold-2)*nx;
01337                         y3 = (inyold-1)*nx;
01338                         y4 = inyold*nx;
01339                         y5 = (inyold+1)*nx;
01340                         y6 = (inyold+2)*nx;
01341                         y7 = (inyold+3)*nx;
01342 
01343                         z1 = (inzold-3)*nx*ny;
01344                         z2 = (inzold-2)*nx*ny;
01345                         z3 = (inzold-1)*nx*ny;
01346                         z4 = inzold*nx*ny;
01347                         z5 = (inzold+1)*nx*ny;
01348                         z6 = (inzold+2)*nx*ny;
01349                         z7 = (inzold+3)*nx*ny;
01350                 }
01351 
01352                 pixel  = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 +
01353                              data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 +
01354                              data[x7+y1+z1]*tablex7 ) * tabley1 +
01355                            ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 +
01356                              data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 +
01357                              data[x7+y2+z1]*tablex7 ) * tabley2 +
01358                            ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 +
01359                              data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 +
01360                              data[x7+y3+z1]*tablex7 ) * tabley3 +
01361                            ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 +
01362                              data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 +
01363                              data[x7+y4+z1]*tablex7 ) * tabley4 +
01364                            ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 +
01365                              data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 +
01366                              data[x7+y5+z1]*tablex7 ) * tabley5 +
01367                            ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 +
01368                              data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 +
01369                              data[x7+y6+z1]*tablex7 ) * tabley6 +
01370                            ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 +
01371                              data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 +
01372                              data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 +
01373                          ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 +
01374                              data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 +
01375                              data[x7+y1+z2]*tablex7 ) * tabley1 +
01376                            ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 +
01377                              data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 +
01378                              data[x7+y2+z2]*tablex7 ) * tabley2 +
01379                            ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 +
01380                              data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 +
01381                              data[x7+y3+z2]*tablex7 ) * tabley3 +
01382                            ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 +
01383                              data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 +
01384                              data[x7+y4+z2]*tablex7 ) * tabley4 +
01385                            ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 +
01386                              data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 +
01387                              data[x7+y5+z2]*tablex7 ) * tabley5 +
01388                            ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 +
01389                              data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 +
01390                              data[x7+y6+z2]*tablex7 ) * tabley6 +
01391                            ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 +
01392                              data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 +
01393                              data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 +
01394                          ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 +
01395                              data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 +
01396                              data[x7+y1+z3]*tablex7 ) * tabley1 +
01397                            ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 +
01398                              data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 +
01399                              data[x7+y2+z3]*tablex7 ) * tabley2 +
01400                            ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 +
01401                              data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 +
01402                              data[x7+y3+z3]*tablex7 ) * tabley3 +
01403                            ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 +
01404                              data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 +
01405                              data[x7+y4+z3]*tablex7 ) * tabley4 +
01406                            ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 +
01407                              data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 +
01408                              data[x7+y5+z3]*tablex7 ) * tabley5 +
01409                            ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 +
01410                              data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 +
01411                              data[x7+y6+z3]*tablex7 ) * tabley6 +
01412                            ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 +
01413                              data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 +
01414                              data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 +
01415                          ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 +
01416                              data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 +
01417                              data[x7+y1+z4]*tablex7 ) * tabley1 +
01418                            ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 +
01419                              data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 +
01420                              data[x7+y2+z4]*tablex7 ) * tabley2 +
01421                            ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 +
01422                              data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 +
01423                              data[x7+y3+z4]*tablex7 ) * tabley3 +
01424                            ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 +
01425                              data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 +
01426                              data[x7+y4+z4]*tablex7 ) * tabley4 +
01427                            ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 +
01428                              data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 +
01429                              data[x7+y5+z4]*tablex7 ) * tabley5 +
01430                            ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 +
01431                              data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 +
01432                              data[x7+y6+z4]*tablex7 ) * tabley6 +
01433                            ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 +
01434                              data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 +
01435                              data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 +
01436                          ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 +
01437                              data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 +
01438                              data[x7+y1+z5]*tablex7 ) * tabley1 +
01439                            ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 +
01440                              data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 +
01441                              data[x7+y2+z5]*tablex7 ) * tabley2 +
01442                            ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 +
01443                              data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 +
01444                              data[x7+y3+z5]*tablex7 ) * tabley3 +
01445                            ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 +
01446                              data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 +
01447                              data[x7+y4+z5]*tablex7 ) * tabley4 +
01448                            ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 +
01449                              data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 +
01450                              data[x7+y5+z5]*tablex7 ) * tabley5 +
01451                            ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 +
01452                              data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 +
01453                              data[x7+y6+z5]*tablex7 ) * tabley6 +
01454                            ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 +
01455                              data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 +
01456                              data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 +
01457                          ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 +
01458                              data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 +
01459                              data[x7+y1+z6]*tablex7 ) * tabley1 +
01460                            ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 +
01461                              data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 +
01462                              data[x7+y2+z6]*tablex7 ) * tabley2 +
01463                            ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 +
01464                              data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 +
01465                              data[x7+y3+z6]*tablex7 ) * tabley3 +
01466                            ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 +
01467                              data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 +
01468                              data[x7+y4+z6]*tablex7 ) * tabley4 +
01469                            ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 +
01470                              data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 +
01471                              data[x7+y5+z6]*tablex7 ) * tabley5 +
01472                            ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 +
01473                              data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 +
01474                              data[x7+y6+z6]*tablex7 ) * tabley6 +
01475                            ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 +
01476                              data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 +
01477                              data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 +
01478                          ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 +
01479                              data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 +
01480                              data[x7+y1+z7]*tablex7 ) * tabley1 +
01481                            ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 +
01482                              data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 +
01483                              data[x7+y2+z7]*tablex7 ) * tabley2 +
01484                            ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 +
01485                              data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 +
01486                              data[x7+y3+z7]*tablex7 ) * tabley3 +
01487                            ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 +
01488                              data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 +
01489                              data[x7+y4+z7]*tablex7 ) * tabley4 +
01490                            ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 +
01491                              data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 +
01492                              data[x7+y5+z7]*tablex7 ) * tabley5 +
01493                            ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 +
01494                              data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 +
01495                              data[x7+y6+z7]*tablex7 ) * tabley6 +
01496                            ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 +
01497                              data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 +
01498                              data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7;
01499 
01500                 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) *
01501                     (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) *
01502                     (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7);
01503         }
01504         return pixel/w;
01505 }

unsigned long int Util::get_randnum_seed  )  [static]
 

Get the seed for Randnum class.

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

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

19623                                                        {
19624 
19625         int nx = vol->get_xsize();
19626         int ny = vol->get_ysize();
19627         int nz = vol->get_zsize();
19628         float *vol_data = vol->get_data();
19629         int new_nx, new_ny;
19630 
19631         if (nz == 1)
19632                 throw ImageDimensionException("Error: Input must be a 3-D object");
19633         if ((dim < 1) || (dim > 3))
19634                 throw ImageDimensionException("Error: dim must be 1 (x-dimension), 2 (y-dimension) or 3 (z-dimension)");
19635         if (((dim == 1) && (index < 0 || index > nx-1)) ||
19636           ((dim == 1) && (index < 0 || index > nx-1)) ||
19637           ((dim == 1) && (index < 0 || index > nx-1)))
19638                 throw ImageDimensionException("Error: index exceeds the size of the 3-D object");
19639 
19640         if (dim == 1) {
19641                 new_nx = ny;
19642                 new_ny = nz;
19643         } else if (dim == 2) {
19644                 new_nx = nx;
19645                 new_ny = nz;
19646         } else {
19647                 new_nx = nx;
19648                 new_ny = ny;
19649         }
19650 
19651         EMData *slice = new EMData();
19652         slice->set_size(new_nx, new_ny, 1);
19653         float *slice_data = slice->get_data();
19654 
19655         if (dim == 1) {
19656                 for (int x=0; x<new_nx; x++)
19657                         for (int y=0; y<new_ny; y++)
19658                                 slice_data[y*new_nx+x] = vol_data[(y*ny+x)*nx+index];
19659         } else if (dim == 2) {
19660                 for (int x=0; x<new_nx; x++)
19661                         for (int y=0; y<new_ny; y++)
19662                                 slice_data[y*new_nx+x] = vol_data[(y*ny+index)*nx+x];
19663         } else {
19664                 for (int x=0; x<new_nx; x++)
19665                         for (int y=0; y<new_ny; y++)
19666                                 slice_data[y*new_nx+x] = vol_data[(index*ny+y)*nx+x];
19667         }
19668 
19669         return slice;
19670 }

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 874 of file util.cpp.

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

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

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

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

Definition at line 930 of file util.cpp.

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

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

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

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

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

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

Definition at line 359 of file util.cpp.

References NullPointerException.

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

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

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

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

Definition at line 344 of file util.cpp.

References NullPointerException.

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

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

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

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

Definition at line 330 of file util.cpp.

References NullPointerException.

Referenced by main().

00331 {
00332         if (!s || !float_var || !p_val) {
00333                 throw NullPointerException("string float");
00334         }
00335         size_t n = strlen(float_var);
00336         if (strncmp(s, float_var, n) == 0) {
00337                 *p_val = (float) atof(&s[n]);
00338                 return true;
00339         }
00340 
00341         return false;
00342 }

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

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

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

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

Definition at line 409 of file util.cpp.

References NullPointerException.

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

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

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

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

Definition at line 395 of file util.cpp.

References NullPointerException.

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

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

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

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

Definition at line 381 of file util.cpp.

References NullPointerException.

Referenced by main().

00382 {
00383         if (!s || !int_var || !p_val) {
00384                 throw NullPointerException("string int");
00385         }
00386 
00387         size_t n = strlen(int_var);
00388         if (strncmp(s, int_var, n) == 0) {
00389                 *p_val = atoi(&s[n]);
00390                 return true;
00391         }
00392         return false;
00393 }

string Util::get_time_label  )  [static]
 

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

Returns:
The current time string.

Definition at line 1095 of file util.cpp.

References t.

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

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 1160 of file util.cpp.

References abs, printmatrix(), printvector(), q, rhs, V, and W.

Referenced by EMAN::FourierInserter3DMode8::init().

01161 {
01162         int i = 0;
01163         int discs = (int)(1+2*freq_cutoff/dfreq);
01164 
01165         float*  W = new float[discs];
01166 
01167         int fc = (int)(2*freq_cutoff + 1);
01168         gsl_matrix* M = gsl_matrix_calloc(fc,fc);
01169 
01170         gsl_vector* rhs = gsl_vector_calloc(fc);
01171         cout << i++ << endl;
01172         for(int k = -freq_cutoff; k <= freq_cutoff; ++k){
01173                 for(int kp = -freq_cutoff; kp <= freq_cutoff; ++kp){
01174                         int kdiff =abs( k-kp);
01175                         int evenoddfac = ( kdiff % 2 == 0 ? 1 : -1);
01176 
01177                         if (kdiff !=0){
01178                                 float val = sin(M_PI*(float)kdiff*r)/(sin(M_PI*(float)kdiff/(float)P))*(alpha+2.0f*beta*evenoddfac);
01179                                 gsl_matrix_set(M,int(k+freq_cutoff),int(kp+freq_cutoff),val);
01180                         }
01181                 }
01182                 gsl_matrix_set(M,int(k+freq_cutoff),int(k+freq_cutoff),r*P* (alpha+2*beta));
01183                 float val = alpha*sin(M_PI*k*r)/(sin(M_PI*(float)k/(float)P));
01184                 if (k!=0) {
01185                         gsl_vector_set(rhs,int(k+freq_cutoff),val);
01186                 }
01187         }
01188         printmatrix(M,fc,fc,"M");
01189 
01190         gsl_vector_set(rhs,int(freq_cutoff),alpha*r*P);
01191         gsl_matrix* V = gsl_matrix_calloc(fc,fc);
01192         gsl_vector* S = gsl_vector_calloc(fc);
01193         gsl_vector* soln = gsl_vector_calloc(fc);
01194         gsl_linalg_SV_decomp(M,V,S,soln);
01195 
01196         gsl_linalg_SV_solve(M, V, S, rhs, soln); // soln now runs from -freq_cutoff to + freq_cutoff
01197         printvector(soln,fc,"soln");
01198 
01199         // we want to solve for W, which ranges from -freq_cutoff to +freq_cutoff in steps of dfreq                            2
01200         int Count=0;
01201         for(float q = (float)(-freq_cutoff); q <= (float)(freq_cutoff); q+= dfreq){
01202                 float temp=0;
01203                 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){
01204                         float dtemp;
01205                         if (q!=k) {
01206                                 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));
01207                         } else{
01208                                 dtemp = (1/(float) P)* (float)gsl_vector_get(soln,int(k+freq_cutoff))  * P;
01209                         }
01210                         temp +=dtemp;
01211                 }
01212                 W[Count]=temp;
01213                 cout << W[Count] << " ";
01214                 Count+=1;
01215         }
01216         cout << endl;
01217         return W;
01218 }

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

Definition at line 1900 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 1883 of file util.h.

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

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

Definition at line 5571 of file util_sparx.cpp.

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

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

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

Definition at line 5479 of file util_sparx.cpp.

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

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

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

Definition at line 5421 of file util_sparx.cpp.

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

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

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

Definition at line 7131 of file util_sparx.cpp.

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

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

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 1591 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 1646 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 1635 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 1624 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 1613 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 1602 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>4095 || y>4095) return (float)hypot((float)x,(float)y);           // We won't cache anything bigger than 4096^2
00722         dim=dim==0?128:dim*2;
00723         mem=(float*)realloc(mem,4*dim*dim);
00724         for (int y=0; y<dim; y++) {
00725                 for (int x=0; x<dim; x++) {
00726 #ifdef  _WIN32
00727                         mem[x+y*dim]=(float)_hypot((float)x,(float)y);
00728 #else
00729                         mem[x+y*dim]=hypot((float)x,(float)y);
00730 #endif
00731                 }
00732         }
00733 }
00734 
00735 return mem[x+y*dim];
00736 }

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

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

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

Definition at line 738 of file util.cpp.

References abs, and round().

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

00739 {
00740 static short *mem = (short *)malloc(2*128*128);
00741 static int dim = 0;
00742 x=abs(x);
00743 y=abs(y);
00744 
00745 if (x>=dim || y>=dim) {
00746         if (x>4095 || y>4095) return (short)hypot((float)x,(float)y);           // We won't cache anything bigger than 4096^2
00747         dim=dim==0?128:dim*2;
00748         mem=(short*)realloc(mem,2*dim*dim);
00749         for (int y=0; y<dim; y++) {
00750                 for (int x=0; x<dim; x++) {
00751 #ifdef  _WIN32
00752                         mem[x+y*dim]=(short)Util::round(_hypot((float)x,(float)y));
00753 #else
00754                         mem[x+y*dim]=(short)Util::round(hypot((float)x,(float)y));
00755 #endif
00756                 }
00757         }
00758 }
00759 
00760 return mem[x+y*dim];
00761 }

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

Definition at line 144 of file util_sparx.cpp.

References B, ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), ImageFormatException, EMAN::EMUtil::is_same_size(), LOGERR, nx, ny, EMAN::EMData::set_size(), EMAN::EMData::to_one(), and EMAN::EMData::update().

00145 {
00146         ENTERFUNC;
00147 
00148         if (!EMUtil::is_same_size(V1, V2)) {
00149                 LOGERR("images not same size");
00150                 throw ImageFormatException( "images not same size");
00151         }
00152 
00153         size_t nx = V1->get_xsize();
00154         size_t ny = V1->get_ysize();
00155         size_t nz = V1->get_zsize();
00156         size_t size = nx*ny*nz;
00157 
00158         EMData *BD = new EMData();
00159         BD->set_size(nx, ny, nz);
00160 
00161         float *params = new float[2];
00162 
00163         float *V1ptr, *V2ptr, *MASKptr, *BDptr, A, B;
00164         long double S1=0.L,S2=0.L,S3=0.L,S4=0.L;
00165         int nvox = 0L;
00166 
00167         V1ptr = V1->get_data();
00168         V2ptr = V2->get_data();
00169         BDptr = BD->get_data();
00170 
00171 
00172         if(!mask){
00173                 EMData * Mask = new EMData();
00174                 Mask->set_size(nx,ny,nz);
00175                 Mask->to_one();
00176                 MASKptr = Mask->get_data();
00177         } else {
00178                 if (!EMUtil::is_same_size(V1, mask)) {
00179                         LOGERR("mask not same size");
00180                         throw ImageFormatException( "mask not same size");
00181                 }
00182 
00183                 MASKptr = mask->get_data();
00184         }
00185 
00186 
00187 
00188 //       calculation of S1,S2,S3,S3,nvox
00189 
00190         for (size_t i = 0L;i < size; i++) {
00191               if (MASKptr[i]>0.5f) {
00192                S1 += V1ptr[i]*V2ptr[i];
00193                S2 += V1ptr[i]*V1ptr[i];
00194                S3 += V2ptr[i];
00195                S4 += V1ptr[i];
00196                nvox ++;
00197               }
00198         }
00199 
00200         if ((nvox*S1 - S3*S4) == 0. || (nvox*S2 - S4*S4) == 0) {
00201                 A =1.0f ;
00202         } else {
00203                 A = static_cast<float>( (nvox*S1 - S3*S4)/(nvox*S2 - S4*S4) );
00204         }
00205         B = static_cast<float> (A*S4  -  S3)/nvox;
00206 
00207         // calculation of the difference image
00208 
00209         for (size_t i = 0L;i < size; i++) {
00210              if (MASKptr[i]>0.5f) {
00211                BDptr[i] = A*V1ptr[i] -  B  - V2ptr[i];
00212              }  else  {
00213                BDptr[i] = 0.f;
00214              }
00215         }
00216 
00217         BD->update();
00218 
00219         params[0] = A;
00220         params[1] = B;
00221 
00222         Dict BDnParams;
00223         BDnParams["imdiff"] = BD;
00224         BDnParams["A"] = params[0];
00225         BDnParams["B"] = params[1];
00226 
00227         EXITFUNC;
00228         return BDnParams;
00229  }

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

Definition at line 19672 of file util_sparx.cpp.

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

19672                                                           {
19673         int nx = img->get_xsize();
19674         float min = img->get_attr("minimum");
19675         float max = img->get_attr("maximum");
19676         float* img_data = img->get_data();
19677         array_mutation(img_data, nx*nx, mutation_rate, min, max, 8, 0);
19678         return;
19679 }

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 < nx*ny*nz; i++) {
00115               if (maskptr[i]>0.5f == flip) {
00116                 Sum1 += Volptr[i];
00117                 Sum2 += Volptr[i]*Volptr[i];
00118                 MAX = (MAX < Volptr[i])?Volptr[i]:MAX;
00119                 MIN = (MIN > Volptr[i])?Volptr[i]:MIN;
00120                 count++;
00121               }
00122         }
00123 
00124         if (count == 0) {
00125                 LOGERR("Invalid mask");
00126                 throw ImageFormatException( "Invalid mask");
00127         }
00128 
00129        float avg = static_cast<float>(Sum1/count);
00130        float sig2 = static_cast<float>(Sum2 - count*avg*avg)/(count-1);
00131        float sig = sqrt(sig2);
00132 
00133        stats.push_back(avg);
00134        stats.push_back(sig);
00135        stats.push_back(MIN);
00136        stats.push_back(MAX);
00137 
00138        return stats;
00139 }

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

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

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

Definition at line 20204 of file util_sparx.cpp.

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

20204                                                                                                    {
20205         //cout<<"initial_prune\n";
20206         // simple initial pruning. For class indClass of partition indPart:
20207         // 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
20208         // If for some partition (not equal to indPart) for which there is no such class, then return 0 immediately.
20209 
20210         // 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
20211 
20212         // remember when calling k_means_cont_table, the first element of each class is an index, and actual number of elements in the class
20213         // (as stored in dimClasses) should be decremented by 1 accordingly, and second is dummy variable
20214 
20215         int* dummy(0);
20216         int* cref;
20217         int cref_size;
20218         int* ccomp;
20219         int ccomp_size;
20220         int nintx;
20221         for (int i=0; i < nParts; i++){
20222                 for (int j =0; j < K; j++){
20223 
20224                         // consider class Parts[i][j]
20225                         cref = Parts[i][j];//incr by 1 since first element is index and second is dummy
20226                         cref_size = (*(dimClasses+i*K+(*cref)))-2;
20227 
20228 
20229                         if (cref_size <= T){
20230 
20231                                 *cref = -1;
20232                                 continue;
20233                         }
20234                         bool done = 0;
20235                         for (int a = 0; a < nParts; a++){
20236                                 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
20237                                 bool hasActive=0;
20238                                 for (unsigned int b=0; b < Parts[a].size(); b++){
20239                                         // get the card of the intx between Parts[i][j] and Parts[a][b] using k_means_cont_table
20240                                         // remember first element of each class is the index of the class
20241                                         ccomp = Parts[a][b];
20242                                         ccomp_size= (*(dimClasses+a*K+(*ccomp)))-2;
20243                                         nintx = Util::k_means_cont_table_(cref+2,ccomp+2, dummy, cref_size, ccomp_size,0);
20244 
20245 
20246                                         if (nintx <= T)
20247                                                 *(ccomp+1) = 0; // class Parts[a][b] is 'inactive' for cref
20248                                         else{
20249                                                 *(ccomp+1)=1; // class Parts[a][b] is 'active' for cref
20250                                                 hasActive=1;
20251                                         }
20252                                 }
20253                                 // see if partition a has at least one active class.if not then we're done with cref
20254                                 if (hasActive < 1){
20255                                    done=1;
20256                                    break;
20257                                 }
20258 
20259                         }
20260 
20261                         if (done > 0){
20262                                 // remove class j from partition i
20263 
20264                                 *cref = -1; // mark for deletion later
20265                                 continue; // move on to class Parts[i][j+1]
20266                         }
20267 
20268                         // now we adopt more aggressive measures. we find the match with the largest weight which has class Parts[i][j] for partition i.
20269                         // 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.
20270 
20271                         // (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.
20272                         // Note that if there are ALOT of partitions, then sorting the partititions may actually take longer than the time saved by ordering hte
20273                         // partitions. However, we do not have a lot of partitions, (usually around 10), so sorting time will be trivial compared to exploring time.
20274 
20275                         // explore returns one if there is a feasible matching containing class cref which has weight gt T, and otherwise returns 0
20276                         //bool found = 1;
20277                         bool found = explore(Parts, dimClasses, nParts, K, T, i, cref+2, cref_size, cref, cref_size,0);
20278 
20279                         if (found<1){ // There is NO feasible matching with class j (cref)  with weight greater than T, so delete this class from Parts
20280                                 // Parts[i].erase(Parts[i].begin()+j);
20281                                 *cref = -1;
20282                         }
20283                 }
20284 
20285                 // Erase from Parts[i] all the classes that's being designated for erasure
20286 
20287                 for (int d = K-1; d > -1; d--){
20288                         if (*(Parts[i][d]) < 0) Parts[i].erase(Parts[i].begin()+d);
20289                 }
20290 
20291         }
20292 
20293         // Print out how many classes are left in each partition
20294         //for (int i =0; i < nParts; i++)
20295         //      cout << Parts[i].size()<<", ";
20296         //cout << "\n";
20297 }

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

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

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

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

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

Definition at line 5108 of file util_sparx.cpp.

References max.

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

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

Calculate linear interpolation.

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

References q, and t.

19735                                                                                                                              {
19736 
19737         if (is_mirror != 0) {
19738                 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) {
19739                         int r = rand()%10000;
19740                         float f = r/10000.0f;
19741                         if (f < mutation_rate) *q = 1-*q;
19742                 }
19743         } else {
19744                 map<int, vector<int> >  graycode;
19745                 map<vector<int>, int> rev_graycode;
19746                 vector <int> gray;
19747 
19748                 int K=1;
19749                 for (int i=0; i<L; i++) K*=2;
19750 
19751                 for (int k=0; k<K; k++) {
19752                         int shift = 0;
19753                         vector <int> gray;
19754                         for (int i=L-1; i>-1; i--) {
19755                                 int t = ((k>>i)%2-shift)%2;
19756                                 gray.push_back(t);
19757                                 shift += t-2;
19758                         }
19759                         graycode[k] = gray;
19760                         rev_graycode[gray] = k;
19761                 }
19762 
19763                 float gap = (K-1)/(max_val-min_val);
19764                 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) {
19765                         float val = *q;
19766                         if (val < min_val) { val = min_val; }
19767                         else if  (val > max_val) { val = max_val; }
19768                         int k = int((val-min_val)*gap+0.5);
19769                         vector<int> gray = graycode[k];
19770                         bool changed = false;
19771                         for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) {
19772                                 int r = rand()%10000;
19773                                 float f = r/10000.0f;
19774                                 if (f < mutation_rate) {
19775                                         *p = 1-*p;
19776                                         changed = true;
19777                                 }
19778                         }
19779                         if (changed) {
19780                                 k = rev_graycode[gray];
19781                                 *q = k/gap+min_val;
19782                         }
19783                 }
19784         }
19785         return list;
19786 }

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

References cl1().

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

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

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

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

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

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

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

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

Definition at line 6120 of file util_sparx.cpp.

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

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

helper function for k-means

Definition at line 5033 of file util_sparx.cpp.

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

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

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

k-means helper

Definition at line 4998 of file util_sparx.cpp.

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

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

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

Definition at line 1035 of file util.h.

Referenced by cluster_pairwise().

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

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

18912 {
18913         ENTERFUNC;
18914         /* Exception Handle */
18915         if (!img) {
18916                 throw NullPointerException("NULL input image");
18917         }
18918 
18919         int newx, newy, newz;
18920         bool  keep_going;
18921         cout << " entered   " <<endl;
18922         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
18923         //int size = nx*ny*nz;
18924         EMData * img2 = new EMData();
18925         img2->set_size(nx,ny,nz);
18926         img2->to_zero();
18927         float *img_ptr  =img->get_data();
18928         float *img2_ptr = img2->get_data();
18929         int r2 = ro*ro;
18930         int r3 = r2*ro;
18931         int ri2 = ri*ri;
18932         int ri3 = ri2*ri;
18933 
18934         int n2 = nx/2;
18935 
18936         for (int k=-n2; k<=n2; k++) {           //cout << " k   "<<k <<endl;
18937                 float z2 = static_cast<float>(k*k);
18938                 for (int j=-n2; j<=n2; j++) {
18939                         float y2 = z2 + j*j;
18940                         if(y2 <= r2) {
18941                                                                                         //cout << "  j  "<<j <<endl;
18942 
18943                                 for (int i=-n2; i<=n2; i++) {
18944                                         float x2 = y2 + i*i;
18945                                         if(x2 <= r3) {
18946                                                                                         //cout << "  i  "<<i <<endl;
18947                                                 int ib = i+n2; int jb = j+n2; int kb = k+n2;
18948                                                 if(x2 >= ri3) {
18949                                                         //  this is the outer shell, here points can only vanish
18950                                                         if(img_ptr(ib,jb,kb) == 1.0f) {
18951                                                                 //cout << "  1  "<<ib <<endl;
18952                                                                 if(Util::get_frand(0.0f, 1.0f) > qprob){
18953                                                                         img2_ptr(ib,jb,kb) = 0.0f;
18954                                                                         keep_going = true;
18955                                                                 //cout << "  try  "<<ib <<endl;
18956                                                                         while(keep_going) {
18957                                                                                 newx = Util::get_irand(-ro,ro);
18958                                                                                 newy = Util::get_irand(-ro,ro);
18959                                                                                 newz = Util::get_irand(-ro,ro);
18960                                                                                 if(newx*newx+newy*newy+newz*newz <= r3) {
18961                                                                                         newx += n2; newy += n2; newz += n2;
18962                                                                                         if( img_ptr(newx,newy,newz) == 0.0f) {
18963                                                                                                 img2_ptr(newx,newy,newz) = 1.0f;
18964                                                                                                 keep_going = false; }
18965                                                                                 }
18966                                                                         }
18967                                                                 }   else  img2_ptr(ib,jb,kb) = 1.0f;
18968                                                         }
18969                                                 }  else  {
18970                                                         // this is inner shell, the point can only move (or vanish, if all neighbors exist)
18971                                                         if(img_ptr(ib,jb,kb) == 1.0) {
18972                                                                 if(Util::get_frand(0.0f,1.0f) > qprob) {
18973                                                                         //  find out the number of neighbors
18974                                                                         float  numn = -1.0f;  // we already know the central one is 1
18975                                                                         for (newz = -1; newz <= 1; newz++)
18976                                                                                 for (newy = -1; newy <= 1; newy++)
18977                                                                                         for (newx = -1; newx <= 1; newx++)
18978                                                                                                 numn += img_ptr(ib+newx,jb+newy,kb+newz);
18979                                                                         img2_ptr(ib,jb,kb) = 0.0;
18980                                                                         if(numn == 26.0f) {
18981                                                                                 //  all neighbors exist, it has to vanish
18982                                                                                 keep_going = true;
18983                                                                                 while(keep_going) {
18984                                                                                         newx = Util::get_irand(-ro,ro);
18985                                                                                         newy = Util::get_irand(-ro,ro);
18986                                                                                         newz = Util::get_irand(-ro,ro);
18987                                                                                         if(newx*newx+newy*newy+newz*newz < r3) {
18988                                                                                                 newx += n2; newy += n2; newz += n2;
18989                                                                                                 if( img_ptr(newx,newy,newz) == 0.0f) {
18990                                                                                                         if(newx*newx+newy*newy+newz*newz < r3) {
18991                                                                                                                 if(newx*newx+newy*newy+newz*newz < r3) {
18992                                                                                                                         newx += n2; newy += n2; newz += n2;
18993                                                                                                                         if( img_ptr(newx,newy,newz) == 0.0f) {
18994                                                                                                                                 img2_ptr(newx,newy,newz) = 1.0f;
18995                                                                                                                                 keep_going = false; }
18996                                                                                                                 }
18997                                                                                                         }
18998                                                                                                 }
18999                                                                                         }
19000                                                                                 }
19001                                                                         }  else if(numn == 25.0f) {
19002                                                                                 // there is only one empty neighbor, move there
19003                                                                                 for (newz = -1; newz <= 1; newz++) {
19004                                                                                         for (newy = -1; newy <= 1; newy++) {
19005                                                                                                 for (newx = -1; newx <= 1; newx++) {
19006                                                                                                         if( newx != 0 && newy != 0 && newz != 0) {
19007                                                                                                                 if(img_ptr(newx+ib,newy+jb,newz+kb) == 0.0f) {
19008                                                                                                                         img2_ptr(newx+ib,newy+jb,newz+kb) = 1.0f;
19009                                                                                                                         }
19010                                                                                                         }
19011                                                                                                 }
19012                                                                                         }
19013                                                                                 }
19014                                                                         }  else {
19015                                                                                 //  more than one neighbor is zero, select randomly one and move there
19016                                                                                 keep_going = true;
19017                                                                                 while(keep_going) {
19018                                                                                         newx = Util::get_irand(-1,1);
19019                                                                                         newy = Util::get_irand(-1,1);
19020                                                                                         newz = Util::get_irand(-1,1);
19021                                                                                         if(newx != 0 && newy != 0 && newz != 0)  {
19022                                                                                                 if(img_ptr(ib+newx,jb+newy,kb+newz) == 0.0f) {
19023                                                                                                         img2_ptr(ib+newx,jb+newy,kb+newz) = 1.0f;//?????
19024                                                                                                         keep_going = false;
19025                                                                                                 }
19026                                                                                         }
19027                                                                                 }
19028                                                                         }
19029                                                                 }  else img2_ptr(ib,jb,kb) = 1.0f;
19030                                                         }
19031                                                 }
19032                                         }
19033                                 }
19034                         }
19035                 }
19036         }
19037         //for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + Util::get_irand(1,7);
19038         img2->update();
19039 
19040         EXITFUNC;
19041         return img2;
19042 }

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

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

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

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

Definition at line 17456 of file util_sparx.cpp.

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

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

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

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

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

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

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

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

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

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

18241                                                       {
18242 
18243         int   maxrin = numr[numr.size()-1];
18244 
18245         int   ky = int(2*yrng/step+0.5)/2;
18246         int   kx = int(2*xrng/step+0.5)/2;
18247 
18248         peaks->set_size(maxrin, 2*kx+3, 2*ky+3);
18249         float *p_ccf1ds = peaks->get_data();
18250 
18251         peakm->set_size(maxrin, 2*kx+3, 2*ky+3);
18252         float *p_ccf1dm = peakm->get_data();
18253 
18254         for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) {
18255                 p_ccf1ds[i] = -1.e20f;
18256                 p_ccf1dm[i] = -1.e20f;
18257         }
18258 
18259         for (int i = -ky; i <= ky; i++) {
18260                 float iy = i * step;
18261                 for (int j = -kx; j <= kx; j++) {
18262                         float ix = j*step;
18263                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18264                         Frngs(cimage, numr);
18265                         Crosrng_msg_vec(crefim, cimage, numr,
18266                           p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin,
18267                           p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin);
18268                         delete cimage; cimage = 0;
18269                 }
18270         }
18271         return;
18272 }

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

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

18276                                                      {
18277 
18278         int   maxrin = numr[numr.size()-1];
18279 
18280         int   ky = int(2*yrng/step+0.5)/2;
18281         int   kx = int(2*xrng/step+0.5)/2;
18282 
18283         peaks->set_size(maxrin, 2*kx+3, 2*ky+3);
18284         float *p_ccf1ds = peaks->get_data();
18285 
18286         peakm->set_size(maxrin, 2*kx+3, 2*ky+3);
18287         float *p_ccf1dm = peakm->get_data();
18288 
18289         peaks_compress->set_size(maxrin, 1, 1);
18290         float *p_ccf1ds_compress = peaks_compress->get_data();
18291 
18292         peakm_compress->set_size(maxrin, 1, 1);
18293         float *p_ccf1dm_compress = peakm_compress->get_data();
18294 
18295         for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) {
18296                 p_ccf1ds[i] = -1.e20f;
18297                 p_ccf1dm[i] = -1.e20f;
18298         }
18299 
18300         for (int i = -ky; i <= ky; i++) {
18301                 float iy = i * step;
18302                 for (int j = -kx; j <= kx; j++) {
18303                         float ix = j*step;
18304                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18305                         Frngs(cimage, numr);
18306                         Crosrng_msg_vec(crefim, cimage, numr,
18307                           p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin,
18308                           p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin);
18309                         delete cimage; cimage = 0;
18310                 }
18311         }
18312         for (int x=0; x<maxrin; x++) {
18313                 float maxs = -1.0e22f;
18314                 float maxm = -1.0e22f;
18315                 for (int i=1; i<=2*ky+1; i++) {
18316                         for (int j=1; j<=2*kx+1; j++) {
18317                                 if (p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x] > maxs) maxs = p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x];
18318                                 if (p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x] > maxm) maxm = p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x];
18319                         }
18320                 }
18321                 p_ccf1ds_compress[x] = maxs;
18322                 p_ccf1dm_compress[x] = maxm;
18323         }
18324         return;
18325 }

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

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

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

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

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

17854                                                                                        {
17855 
17856     // Manually extract.
17857 /*    vector< EMAN::EMData* > crefim;
17858     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
17859     crefim.reserve(crefim_len);
17860 
17861     for(std::size_t i=0;i<crefim_len;i++) {
17862         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
17863         crefim.push_back(proxy());
17864     }
17865 */
17866 
17867         size_t crefim_len = crefim.size();
17868 
17869         int   ky = int(2*yrng/step+0.5)/2;
17870         int   kx = int(2*xrng/step+0.5)/2;
17871         int   iref, nref=0, mirror=0;
17872         float iy, ix, sx=0, sy=0;
17873         float peak = -1.0E23f;
17874         float ang=0.0f;
17875         for (int i = -ky; i <= ky; i++) {
17876                 iy = i * step ;
17877                 for (int j = -kx; j <= kx; j++) {
17878                         ix = j*step ;
17879                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
17880 
17881                         Normalize_ring( cimage, numr );
17882 
17883                         Frngs(cimage, numr);
17884                         //  compare with all reference images
17885                         // for iref in xrange(len(crefim)):
17886                         for ( iref = 0; iref < (int)crefim_len; iref++) {
17887                                 Dict retvals = Crosrng_ms_delta(crefim[iref], cimage, numr, delta_start, delta);
17888                                 double qn = retvals["qn"];
17889                                 double qm = retvals["qm"];
17890                                 if(qn >= peak || qm >= peak) {
17891                                         sx = -ix;
17892                                         sy = -iy;
17893                                         nref = iref;
17894                                         if (qn >= qm) {
17895                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
17896                                                 peak = static_cast<float>(qn);
17897                                                 mirror = 0;
17898                                         } else {
17899                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
17900                                                 peak = static_cast<float>(qm);
17901                                                 mirror = 1;
17902                                         }
17903                                 }
17904                         }  delete cimage; cimage = 0;
17905                 }
17906         }
17907         float co, so, sxs, sys;
17908         co = static_cast<float>( cos(ang*pi/180.0) );
17909         so = static_cast<float>( -sin(ang*pi/180.0) );
17910         sxs = sx*co - sy*so;
17911         sys = sx*so + sy*co;
17912         vector<float> res;
17913         res.push_back(ang);
17914         res.push_back(sxs);
17915         res.push_back(sys);
17916         res.push_back(static_cast<float>(mirror));
17917         res.push_back(static_cast<float>(nref));
17918         res.push_back(peak);
17919         return res;
17920 }

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

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

17981                                                        {
17982 
17983     // Manually extract.
17984 /*    vector< EMAN::EMData* > crefim;
17985     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
17986     crefim.reserve(crefim_len);
17987 
17988     for(std::size_t i=0;i<crefim_len;i++) {
17989         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
17990         crefim.push_back(proxy());
17991     }
17992 */
17993         size_t crefim_len = crefim.size();
17994         const float qv = static_cast<float>( pi/180.0 );
17995 
17996         Transform * t = image->get_attr("xform.projection");
17997         Dict d = t->get_params("spider");
17998         if(t) {delete t; t=0;}
17999         float phi = d["phi"];
18000         float theta = d["theta"];
18001         int   ky = int(2*yrng/step+0.5)/2;
18002         int   kx = int(2*xrng/step+0.5)/2;
18003         int   iref, nref=0, mirror=0;
18004         float iy, ix, sx=0, sy=0;
18005         float peak = -1.0E23f;
18006         float ang=0.0f;
18007         float imn1 = sin(theta*qv)*cos(phi*qv);
18008         float imn2 = sin(theta*qv)*sin(phi*qv);
18009         float imn3 = cos(theta*qv);
18010         vector<float> n1(crefim_len);
18011         vector<float> n2(crefim_len);
18012         vector<float> n3(crefim_len);
18013         for ( iref = 0; iref < (int)crefim_len; iref++) {
18014                         n1[iref] = crefim[iref]->get_attr("n1");
18015                         n2[iref] = crefim[iref]->get_attr("n2");
18016                         n3[iref] = crefim[iref]->get_attr("n3");
18017         }
18018         for (int i = -ky; i <= ky; i++) {
18019             iy = i * step ;
18020             for (int j = -kx; j <= kx; j++) {
18021                 ix = j*step;
18022                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18023 
18024                 Normalize_ring( cimage, numr );
18025 
18026                 Frngs(cimage, numr);
18027                 //  compare with all reference images
18028                 // for iref in xrange(len(crefim)):
18029                 for ( iref = 0; iref < (int)crefim_len; iref++) {
18030                         if(abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18031                                 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
18032                                 double qn = retvals["qn"];
18033                                 double qm = retvals["qm"];
18034                                 if(qn >= peak || qm >= peak) {
18035                                         sx = -ix;
18036                                         sy = -iy;
18037                                         nref = iref;
18038                                         if (qn >= qm) {
18039                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18040                                                 peak = static_cast<float>( qn );
18041                                                 mirror = 0;
18042                                         } else {
18043                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18044                                                 peak = static_cast<float>( qm );
18045                                                 mirror = 1;
18046                                         }
18047                                 }
18048                         }
18049                 }  delete cimage; cimage = 0;
18050             }
18051         }
18052         float co, so, sxs, sys;
18053         if(peak == -1.0E23) {
18054                 ang=0.0; sxs=0.0; sys=0.0; mirror=0;
18055                 nref = -1;
18056         } else {
18057                 co =  cos(ang*qv);
18058                 so = -sin(ang*qv);
18059                 sxs = sx*co - sy*so;
18060                 sys = sx*so + sy*co;
18061         }
18062         vector<float> res;
18063         res.push_back(ang);
18064         res.push_back(sxs);
18065         res.push_back(sys);
18066         res.push_back(static_cast<float>(mirror));
18067         res.push_back(static_cast<float>(nref));
18068         res.push_back(peak);
18069         return res;
18070 }

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

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

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

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

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

17924                                                          {
17925 
17926     // Manually extract.
17927 /*    vector< EMAN::EMData* > crefim;
17928     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
17929     crefim.reserve(crefim_len);
17930 
17931     for(std::size_t i=0;i<crefim_len;i++) {
17932         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
17933         crefim.push_back(proxy());
17934     }
17935 */
17936         size_t crefim_len = crefim.size();
17937 
17938         int   ky = int(2*yrng/step+0.5)/2;
17939         int   kx = int(2*xrng/step+0.5)/2;
17940         int   iref, nref=0;
17941         float iy, ix, sx=0, sy=0;
17942         float peak = -1.0E23f;
17943         float ang=0.0f;
17944         for (int i = -ky; i <= ky; i++) {
17945                 iy = i * step ;
17946                 for (int j = -kx; j <= kx; j++) {
17947                         ix = j*step ;
17948                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
17949                         Frngs(cimage, numr);
17950                         //  compare with all reference images
17951                         // for iref in xrange(len(crefim)):
17952                         for ( iref = 0; iref < (int)crefim_len; iref++) {
17953                                 Dict retvals = Crosrng_ns(crefim[iref], cimage, numr);
17954                                 double qn = retvals["qn"];
17955                                 if(qn >= peak) {
17956                                         sx = -ix;
17957                                         sy = -iy;
17958                                         nref = iref;
17959                                         ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
17960                                         peak = static_cast<float>(qn);
17961                                 }
17962                         }  delete cimage; cimage = 0;
17963                 }
17964         }
17965         float co, so, sxs, sys;
17966         co = static_cast<float>( cos(ang*pi/180.0) );
17967         so = static_cast<float>( -sin(ang*pi/180.0) );
17968         sxs = sx*co - sy*so;
17969         sys = sx*so + sy*co;
17970         vector<float> res;
17971         res.push_back(ang);
17972         res.push_back(sxs);
17973         res.push_back(sys);
17974         res.push_back(static_cast<float>(nref));
17975         res.push_back(peak);
17976         return res;
17977 }

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

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

Definition at line 18179 of file util_sparx.cpp.

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

18181                                                        {
18182 
18183         size_t crefim_len = crefim.size();
18184 
18185         int   ky = int(2*yrng/step+0.5)/2;
18186         int   kx = int(2*xrng/step+0.5)/2;
18187         int   iref, nref=0, mirror=0;
18188         float iy, ix, sx=0, sy=0;
18189         float peak = -1.0E23f;
18190         float ang=0.0f;
18191         for (int i = -ky; i <= ky; i++) {
18192                 iy = i * step ;
18193                 for (int j = -kx; j <= kx; j++) {
18194                         ix = j*step ;
18195                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18196 
18197                         Normalize_ring( cimage, numr );
18198 
18199                         Frngs(cimage, numr);
18200                         //  compare with all reference images
18201                         // for iref in xrange(len(crefim)):
18202                         for ( iref = 0; iref < (int)crefim_len; iref++) {
18203                                 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18204                                 double qn = retvals["qn"];
18205                                 double qm = retvals["qm"];
18206                                 if(qn >= peak || qm >= peak) {
18207                                         sx = -ix;
18208                                         sy = -iy;
18209                                         nref = iref;
18210                                         if (qn >= qm) {
18211                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18212                                                 peak = static_cast<float>(qn);
18213                                                 mirror = 0;
18214                                         } else {
18215                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18216                                                 peak = static_cast<float>(qm);
18217                                                 mirror = 1;
18218                                         }
18219                                 }
18220                         }  delete cimage; cimage = 0;
18221                 }
18222         }
18223         float co, so, sxs, sys;
18224         co = static_cast<float>( cos(ang*pi/180.0) );
18225         so = static_cast<float>( -sin(ang*pi/180.0) );
18226         sxs = sx*co - sy*so;
18227         sys = sx*so + sy*co;
18228         vector<float> res;
18229         res.push_back(ang);
18230         res.push_back(sxs);
18231         res.push_back(sys);
18232         res.push_back(static_cast<float>(mirror));
18233         res.push_back(static_cast<float>(nref));
18234         res.push_back(peak);
18235         return res;
18236 }

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

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

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

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

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

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

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

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

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

Definition at line 5265 of file util_sparx.cpp.

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

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

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

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

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

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 1267 of file util.cpp.

References point_is_in_triangle_2d().

01268 {
01269 
01270         if (point_is_in_triangle_2d(p1,p2,p4,actual_point)) return true;
01271         else return point_is_in_triangle_2d(p3,p2,p4,actual_point);
01272 }

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 1232 of file util.cpp.

References EMAN::Vec2< Type >::dot(), EMAN::Transform::ERR_LIMIT, t, and v.

Referenced by point_is_in_convex_polygon_2d().

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

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

Definition at line 2137 of file util_sparx.cpp.

References circ, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), numr, quadri(), EMAN::EMData::set_size(), xim, and y.

02137                                                                   {
02138         int nsam = image->get_xsize();
02139         int nrow = image->get_ysize();
02140         int nring = numr.size()/3;
02141         int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
02142         EMData* out = new EMData();
02143         out->set_size(lcirc,1,1);
02144         char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h';
02145         float *xim  = image->get_data();
02146         float *circ = out->get_data();
02147 /*   alrq(image->get_data(), nsam, nrow, &numr[0], out->get_data(), lcirc, nring, cmode);
02148    return out;
02149 }
02150 void Util::alrq(float *xim,  int nsam , int nrow , int *numr,
02151           float *circ, int lcirc, int nring, char mode)
02152 {*/
02153 /*
02154 c
02155 c  purpose:
02156 c
02157 c  resmaple to polar coordinates
02158 c
02159 */
02160         //  dimension         xim(nsam,nrow),circ(lcirc)
02161         //  integer           numr(3,nring)
02162 
02163         double dfi, dpi;
02164         int    ns2, nr2, i, inr, l, nsim, kcirc, lt, j;
02165         float  yq, xold, yold, fi, x, y;
02166 
02167         ns2 = nsam/2+1;
02168         nr2 = nrow/2+1;
02169         dpi = 2.0*atan(1.0);
02170 
02171         for (i=1;i<=nring;i++) {
02172                 // radius of the ring
02173                 inr = numr(1,i);
02174                 yq  = static_cast<float>(inr);
02175                 l   = numr(3,i);
02176                 if (mode == 'h' || mode == 'H')  lt = l/2;
02177                 else                             lt = l/4;
02178 
02179                 nsim           = lt-1;
02180                 dfi            = dpi/(nsim+1);
02181                 kcirc          = numr(2,i);
02182                 xold           = 0.0f;
02183                 yold           = static_cast<float>(inr);
02184                 circ(kcirc)    = quadri(xold+(float)ns2,yold+(float)nr2,nsam,nrow,xim);
02185                 xold           = static_cast<float>(inr);
02186                 yold           = 0.0f;
02187                 circ(lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02188 
02189                 if (mode == 'f' || mode == 'F') {
02190                         xold              = 0.0f;
02191                         yold              = static_cast<float>(-inr);
02192                         circ(lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02193                         xold              = static_cast<float>(-inr);
02194                         yold              = 0.0f;
02195                         circ(lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02196                 }
02197 
02198                 for (j=1;j<=nsim;j++) {
02199                         fi               = static_cast<float>(dfi*j);
02200                         x                = sin(fi)*yq;
02201                         y                = cos(fi)*yq;
02202                         xold             = x;
02203                         yold             = y;
02204                         circ(j+kcirc)    = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02205                         xold             =  y;
02206                         yold             = -x;
02207                         circ(j+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02208 
02209                         if (mode == 'f' || mode == 'F')  {
02210                                 xold                = -x;
02211                                 yold                = -y;
02212                                 circ(j+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02213                                 xold                = -y;
02214                                 yold                =  x;
02215                                 circ(j+lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02216                         }
02217                 }
02218         }
02219         return  out;
02220 }

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

Definition at line 2222 of file util_sparx.cpp.

References Assert, circ, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), numr, quadri(), EMAN::EMData::set_size(), xim, and y.

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

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

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

Definition at line 2505 of file util_sparx.cpp.

References circ, EMAN::EMData::get_data(), get_pixel_conv_new(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), numr, nx, ny, EMAN::EMData::set_size(), and y.

02505                                                                                                                   {
02506 // input image is twice the size of the original image
02507         int nring = numr.size()/3;
02508         int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
02509         EMData* out = new EMData();
02510         out->set_size(lcirc,1,1);
02511         char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h';
02512         float *circ = out->get_data();
02513         float *fimage = image->get_data();
02514         int nx = image->get_xsize();
02515         int ny = image->get_ysize();
02516         int nz = image->get_zsize();
02517         double dpi, dfi;
02518         int    it, jt, inr, l, nsim, kcirc, lt;
02519         float  yq, xold, yold, fi, x, y;
02520 
02521         //     cns2 and cnr2 are predefined centers
02522         //     no need to set to zero, all elements are defined
02523 
02524         dpi = 2*atan(1.0);
02525         for (it=1;it<=nring;it++) {
02526                 // radius of the ring
02527                 inr = numr(1,it);
02528                 yq  = static_cast<float>(inr);
02529 
02530                 l = numr(3,it);
02531                 if ( mode == 'h' || mode == 'H' )  lt = l / 2;
02532                 else                               lt = l / 4;
02533 
02534                 nsim  = lt - 1;
02535                 dfi   = dpi / (nsim+1);
02536                 kcirc = numr(2,it);
02537                 xold  = 0.0f;
02538                 yold  = static_cast<float>(inr);
02539                 circ(kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02540 //      circ(kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02541 
02542                 xold  = static_cast<float>(inr);
02543                 yold  = 0.0f;
02544                 circ(lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02545 //      circ(lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02546 
02547         if ( mode == 'f' || mode == 'F' ) {
02548                 xold = 0.0f;
02549                 yold = static_cast<float>(-inr);
02550                 circ(lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02551 //         circ(lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02552 
02553                 xold = static_cast<float>(-inr);
02554                 yold = 0.0f;
02555                 circ(lt+lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02556 //         circ(lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02557         }
02558 
02559         for (jt=1;jt<=nsim;jt++) {
02560                 fi   = static_cast<float>(dfi * jt);
02561                 x    = sin(fi) * yq;
02562                 y    = cos(fi) * yq;
02563 
02564                 xold = x;
02565                 yold = y;
02566                 circ(jt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02567 //         circ(jt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02568 
02569                 xold = y;
02570                 yold = -x;
02571                 circ(jt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02572 //         circ(jt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02573 
02574         if ( mode == 'f' || mode == 'F' ) {
02575                 xold = -x;
02576                 yold = -y;
02577                 circ(jt+lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02578 //            circ(jt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02579 
02580                 xold = -y;
02581                 yold = x;
02582                 circ(jt+lt+lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02583 //            circ(jt+lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02584         }
02585         } // end for jt
02586         } //end for it
02587         return  out;
02588 }

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

Definition at line 3126 of file util_sparx.cpp.

References b.

Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ns(), Crosrng_psi_0_180(), and Crosrng_sm_psi().

03126                                                   {
03127         double  c2,c3;
03128         int     nhalf;
03129 
03130         nhalf = npoint/2 + 1;
03131         *pos  = 0.0;
03132 
03133         if (npoint == 7) {
03134                 c2 = 49.*b(1) + 6.*b(2) - 21.*b(3) - 32.*b(4) - 27.*b(5)
03135                      - 6.*b(6) + 31.*b(7);
03136                 c3 = 5.*b(1) - 3.*b(3) - 4.*b(4) - 3.*b(5) + 5.*b(7);
03137         }
03138         else if (npoint == 5) {
03139                 c2 = (74.*b(1) - 23.*b(2) - 60.*b(3) - 37.*b(4)
03140                    + 46.*b(5) ) / (-70.);
03141                 c3 = (2.*b(1) - b(2) - 2.*b(3) - b(4) + 2.*b(5) ) / 14.0;
03142         }
03143         else if (npoint == 3) {
03144                 c2 = (5.*b(1) - 8.*b(2) + 3.*b(3) ) / (-2.0);
03145                 c3 = (b(1) - 2.*b(2) + b(3) ) / 2.0;
03146         }
03147         //else if (npoint == 9) {
03148         else  { // at least one has to be true!!
03149                 c2 = (1708.*b(1) + 581.*b(2) - 246.*b(3) - 773.*b(4)
03150                      - 1000.*b(5) - 927.*b(6) - 554.*b(7) + 119.*b(8)
03151                      + 1092.*b(9) ) / (-4620.);
03152                 c3 = (28.*b(1) + 7.*b(2) - 8.*b(3) - 17.*b(4) - 20.*b(5)
03153                      - 17.*b(6) - 8.*b(7) + 7.*b(8) + 28.*b(9) ) / 924.0;
03154         }
03155         if (c3 != 0.0)  *pos = static_cast<float>(c2/(2.0*c3) - nhalf);
03156 }

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

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

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 1116 of file util.cpp.

References nx, and ny.

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

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

Definition at line 6242 of file util_sparx.cpp.

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

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

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

Quadratic interpolation (2D).

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

This routine uses six image points for interpolation:

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

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

                f3    fc
                |
                | x
         f2-----f0----f1
                |
                |
                f4
		 *

f0 - f4 are image values near the interpolated point X. f0 is the interior mesh point nearest x.

Coords:

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

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

Definition at line 646 of file util_sparx.cpp.

References fdata, x, and y.

Referenced by alrl_ms(), Polar2D(), Polar2Dm(), and quadri_background().

00647 {
00648 //  purpose: quadratic interpolation
00649 //  Optimized for speed, circular closer removed, checking of ranges removed
00650         float  x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb;
00651         float  quadri;
00652         int    i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc;
00653 
00654         x = xx;
00655         y = yy;
00656 
00657         //     any xx and yy
00658         while ( x < 1.0 )                 x += nxdata;
00659         while ( x >= (float)(nxdata+1) )  x -= nxdata;
00660         while ( y < 1.0 )                 y += nydata;
00661         while ( y >= (float)(nydata+1) )  y -= nydata;
00662 
00663         i   = (int) x;
00664         j   = (int) y;
00665 
00666         dx0 = x - i;
00667         dy0 = y - j;
00668 
00669         ip1 = i + 1;
00670         im1 = i - 1;
00671         jp1 = j + 1;
00672         jm1 = j - 1;
00673 
00674         if (ip1 > nxdata) ip1 -= nxdata;
00675         if (im1 < 1)      im1 += nxdata;
00676         if (jp1 > nydata) jp1 -= nydata;
00677         if (jm1 < 1)      jm1 += nydata;
00678 
00679         f0  = fdata(i,j);
00680         c1  = fdata(ip1,j) - f0;
00681         c2  = (c1 - f0 + fdata(im1,j)) * 0.5f;
00682         c3  = fdata(i,jp1) - f0;
00683         c4  = (c3 - f0 + fdata(i,jm1)) * 0.5f;
00684 
00685         dxb = dx0 - 1;
00686         dyb = dy0 - 1;
00687 
00688         // hxc & hyc are either 1 or -1
00689         if (dx0 >= 0) hxc = 1; else hxc = -1;
00690         if (dy0 >= 0) hyc = 1; else hyc = -1;
00691 
00692         ic  = i + hxc;
00693         jc  = j + hyc;
00694 
00695         if (ic > nxdata) ic -= nxdata;  else if (ic < 1) ic += nxdata;
00696         if (jc > nydata) jc -= nydata;  else if (jc < 1) jc += nydata;
00697 
00698         c5  =  ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2
00699                 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc));
00700 
00701 
00702         quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4);
00703 
00704         return quadri;
00705 }

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

Quadratic interpolation (2D).

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

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

This routine uses six image points for interpolation:

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

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

                f3    fc
                |
                | x
         f2-----f0----f1
                |
                |
                f4
		 *

f0 - f4 are image values near the interpolated point X. f0 is the interior mesh point nearest x.

Coords:

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

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

Definition at line 710 of file util_sparx.cpp.

References fdata, quadri(), x, and y.

00711 {
00712 //  purpose: quadratic interpolation
00713 //  Optimized for speed, circular closer removed, checking of ranges removed
00714         float  x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb;
00715         float  quadri;
00716         int    i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc;
00717 
00718         x = xx;
00719         y = yy;
00720 
00721         // wrap around is not done circulantly; if (x,y) is not in the image, then x = xnew and y = ynew
00722         if ( (x < 1.0) || ( x >= (float)(nxdata+1) ) || ( y < 1.0 ) || ( y >= (float)(nydata+1) )){
00723               x = (float)xnew;
00724                   y = (float)ynew;
00725      }
00726 
00727 
00728         i   = (int) x;
00729         j   = (int) y;
00730 
00731         dx0 = x - i;
00732         dy0 = y - j;
00733 
00734         ip1 = i + 1;
00735         im1 = i - 1;
00736         jp1 = j + 1;
00737         jm1 = j - 1;
00738 
00739         if (ip1 > nxdata) ip1 -= nxdata;
00740         if (im1 < 1)      im1 += nxdata;
00741         if (jp1 > nydata) jp1 -= nydata;
00742         if (jm1 < 1)      jm1 += nydata;
00743 
00744         f0  = fdata(i,j);
00745         c1  = fdata(ip1,j) - f0;
00746         c2  = (c1 - f0 + fdata(im1,j)) * 0.5f;
00747         c3  = fdata(i,jp1) - f0;
00748         c4  = (c3 - f0 + fdata(i,jm1)) * 0.5f;
00749 
00750         dxb = dx0 - 1;
00751         dyb = dy0 - 1;
00752 
00753         // hxc & hyc are either 1 or -1
00754         if (dx0 >= 0) hxc = 1; else hxc = -1;
00755         if (dy0 >= 0) hyc = 1; else hyc = -1;
00756 
00757         ic  = i + hxc;
00758         jc  = j + hyc;
00759 
00760         if (ic > nxdata) ic -= nxdata;  else if (ic < 1) ic += nxdata;
00761         if (jc > nydata) jc -= nydata;  else if (jc < 1) jc += nydata;
00762 
00763         c5  =  ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2
00764                 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc));
00765 
00766 
00767         quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4);
00768 
00769         return quadri;
00770 }

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

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

PRB

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

References sort_mat().

00436 {
00437         int iMax = (int) floor( (Size-1.0)/2 +.01);
00438         int CountMax = (iMax+2)*(iMax+1)/2;
00439         int Count=-1;
00440         float *kVals     = new float[CountMax];
00441         float *weightMat = new float[CountMax];
00442         int *PermMat     = new   int[CountMax];
00443         SizeReturned[0] = CountMax;
00444 
00445 //      printf("Aa \n");        fflush(stdout);
00446         for (int jkx=0; jkx< iMax+1; jkx++) {
00447                 for (int jky=0; jky< jkx+1; jky++) {
00448                         Count++;
00449                         kVals[Count] = sqrtf((float) (jkx*jkx +jky*jky));
00450                         weightMat[Count]=  1.0;
00451                         if (jkx!=0)  { weightMat[Count] *=2;}
00452                         if (jky!=0)  { weightMat[Count] *=2;}
00453                         if (jkx!=jky){ weightMat[Count] *=2;}
00454                         PermMat[Count]=Count+1;
00455                 }
00456         }
00457 
00458         int lkVals = Count+1;
00459 //      printf("Cc \n");fflush(stdout);
00460 
00461         sort_mat(&kVals[0],&kVals[Count],
00462              &PermMat[0],  &PermMat[Count]);  //PermMat is
00463                                 //also returned as well as kValsSorted
00464         fflush(stdout);
00465 
00466         int newInd;
00467 
00468         for (int iP=0; iP < lkVals ; iP++ ) {
00469                 newInd =  PermMat[iP];
00470                 PermMatTr[newInd-1] = iP+1;
00471         }
00472 
00473 //      printf("Ee \n"); fflush(stdout);
00474 
00475         int CountA=-1;
00476         int CountB=-1;
00477 
00478         while (CountB< (CountMax-1)) {
00479                 CountA++;
00480                 CountB++;
00481 //              printf("CountA=%d ; CountB=%d \n", CountA,CountB);fflush(stdout);
00482                 kValsSorted[CountA] = kVals[CountB] ;
00483                 if (CountB<(CountMax-1) ) {
00484                         while (fabs(kVals[CountB] -kVals[CountB+1])<.0000001  ) {
00485                                 SizeReturned[0]--;
00486                                 for (int iP=0; iP < lkVals; iP++){
00487 //                                      printf("iP=%d \n", iP);fflush(stdout);
00488                                         if  (PermMatTr[iP]>CountA+1) {
00489                                                 PermMatTr[iP]--;
00490                                         }
00491                                 }
00492                                 CountB++;
00493                         }
00494                 }
00495         }
00496 
00497 
00498         for (int CountD=0; CountD < CountMax; CountD++) {
00499             newInd = PermMatTr[CountD];
00500             weightofkValsSorted[newInd-1] += weightMat[CountD];
00501         }
00502 
00503 }

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

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

string Util::recv_broadcast int  port  )  [static]
 

Definition at line 1039 of file util.cpp.

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

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

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

Referenced by get_pixel_conv_new(), and get_pixel_conv_new_background().

01095                                             {

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

Referenced by EMAN::Util::FakeKaiserBessel::build_I0table(), EMAN::Util::KaiserBessel::build_I0table(), EMAN::Util::sincBlackman::build_sBtable(), EMAN::EMData::calc_fourier_shell_correlation(), EMAN::EMData::calc_hist(), EMAN::EMData::cog(), EMAN::EMData::cut_slice(), EMAN::EMData::extract_plane(), EMAN::EMData::extractline(), EMAN::EMData::extractpoint(), extractpoint2(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), EMAN::EMData::get_pixel_conv(), get_pixel_conv_new(), get_pixel_conv_new_background(), EMAN::EMData::get_pixel_filtered(), hypot_fast_int(), EMAN::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 19865 of file util_sparx.cpp.

References k_means_cont_table_().

19865                                                                                                          {
19866         //cout<<"sanitycheck called\n";
19867         int total_cost = *output;
19868         int num_matches = *(output+1);
19869 
19870         int cost=0;
19871         int* intx;
19872         int intx_size;
19873         int* intx_next(0);
19874         int intx_next_size = 0;
19875         int curclass;
19876         int curclass_size;
19877         //cout<<"cost by match: [";
19878         for(int i = 0; i < num_matches; i++){
19879                 curclass = *(output+2+ i*nParts);
19880                 // check feasibility
19881                 if (*(argParts + Indices[curclass]+1) == -5) {cout<<"infeasible match!\n"; return 0;}
19882                 *(argParts + Indices[curclass]+1) = -5;
19883                 // initialize intx to the number of elements in class curclass of partition 0 of the i-th match
19884                 curclass_size = *(dimClasses+curclass)-2;
19885                 intx = new int[curclass_size];
19886                 for (int ic = 0; ic < curclass_size; ic++) *(intx+ic) = *(argParts + Indices[curclass]+2+ic);
19887                 intx_size = curclass_size;
19888 
19889                 for (int j=1; j < nParts; j++){
19890                       curclass = *(output+2+ i*nParts+j);
19891                       if (*(argParts + Indices[j*K+curclass]+1)==-5){cout<<"infeasible match!\n"; return 0;}
19892                       *(argParts + Indices[j*K+curclass]+1)=-5;
19893                       // compute the intersection of intx and class curclass of partition j of the i-th match
19894                       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);
19895                       intx_next = new int[intx_next_size];
19896                       Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,1);
19897                       delete[] intx;
19898                       intx=intx_next;
19899                       intx_size= intx_next_size;
19900                       if (j==nParts-1) delete[] intx_next;
19901                 }
19902 
19903                 if (intx_next_size <= T) {cout << "something wrong with solution!\n"; return 0;}
19904                 //cout <<intx_next_size<<",";
19905                 cost = cost + intx_next_size;
19906         }
19907         //cout<<"]\n";
19908         if (cost != total_cost) {cout << "something wrong with solution!\n"; return 0;}
19909 
19910         return 1;
19911 
19912 }

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  newT,
int *  curmax
[static]
 

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

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

Definition at line 20092 of file util_sparx.cpp.

References explore2(), and k_means_cont_table_().

20092                                                                                                         {
20093         // initialize the current max weight to 0
20094         *curmax= 0;
20095         // some temp variables
20096         bool flag = 0;
20097         int nintx;
20098         int* dummy(0);
20099         int* ret;
20100 
20101         for(int a=0; a<K; a++)
20102         {
20103                 // check that class a of partition 0 is active and has greater than newT elements. If not the case, then skip to the next class
20104                 if (*(argParts + Indices[a] + 1) < 1) continue;
20105                 if (*(dimClasses + a)-2 <= newT) continue;
20106 
20107                 // 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
20108 
20109                 for( int i=1; i < nParts; i++){
20110                         flag = 0; // if flag stays 0 then no class in this partition is active, which implies no feasible match with class a of part 0
20111                         for(int j=0; j < K; j++){
20112                                 if (*(argParts + Indices[i*K+j] + 1) < 1) continue;
20113                                 if (*(dimClasses + i*K+j)-2 <= newT) {*(argParts + Indices[i*K+j] + 1) =-4; continue;}
20114                                 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);
20115                                 if (nintx > newT) flag=1;
20116                                 else *(argParts + Indices[i*K+j] + 1) =-4;
20117                         }
20118                         if (flag==0) {break;}
20119                 }
20120 
20121                 // explore determines the feasible match with the largest weight greater than newT
20122                 if (flag > 0){ // Each partition has one or more active class
20123                         ret=Util::explore2(argParts, Indices, dimClasses, nParts, K, newT, argParts+Indices[a]+2, *(dimClasses+a)-2, argParts+Indices[a]+2, *(dimClasses+a)-2,0);
20124 
20125                         if (*ret > *curmax){
20126                                 *curmax = *ret;
20127                                 *(curmax+1)=a;
20128                                 for (int cp =0; cp < nParts-1; cp++) *(curmax+2+cp) = *(ret+1+cp);
20129 
20130                         }
20131                         delete[] ret;
20132                 }
20133                 // take all the classes marked as -4 and remark it as 1 in preparation for next round
20134                 for( int i=1; i < nParts; i++){
20135                         for(int j=0; j < K; j++){
20136                                 if (*(argParts + Indices[i*K+j] + 1) == -4) *(argParts + Indices[i*K+j] + 1) =1;
20137 
20138                         }
20139                 }
20140 
20141 
20142 
20143         }
20144 
20145 
20146 }

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

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

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

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

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

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

Definition at line 1106 of file util.cpp.

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

Referenced by main().

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

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

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

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

Definition at line 5359 of file util_sparx.cpp.

References colreverse().

Referenced by cyclicshift().

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

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

does a sort as in Matlab.

Carries along the Permutation matrix

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

00374 {
00375         int i,k;
00376         float p, qn, sig, un, *u;
00377         u = new float[n-1];
00378 
00379         if (yp1 > .99e30){
00380                 y2[0]=u[0]=0.0;
00381         } else {
00382                 y2[0]=-.5f;
00383                 u[0] =(3.0f/ (x[1] -x[0]))*( (y[1]-y[0])/(x[1]-x[0]) -yp1);
00384         }
00385 
00386         for (i=1; i < n-1; i++) {
00387                 sig= (x[i] - x[i-1])/(x[i+1] - x[i-1]);
00388                 p = sig*y2[i-1] + 2.0f;
00389                 y2[i]  = (sig-1.0f)/p;
00390                 u[i] = (y[i+1] - y[i] )/(x[i+1]-x[i] ) -  (y[i] - y[i-1] )/(x[i] -x[i-1]);
00391                 u[i] = (6.0f*u[i]/ (x[i+1]-x[i-1]) - sig*u[i-1])/p;
00392         }
00393 
00394         if (ypn>.99e30){
00395                 qn=0; un=0;
00396         } else {
00397                 qn= .5f;
00398                 un= (3.0f/(x[n-1] -x[n-2])) * (ypn -  (y[n-1]-y[n-2])/(x[n-1]-x[n-2]));
00399         }
00400         y2[n-1]= (un - qn*u[n-2])/(qn*y2[n-2]+1.0f);
00401         for (k=n-2; k>=0; k--){
00402                 y2[k]=y2[k]*y2[k+1]+u[k];
00403         }
00404         delete [] u;
00405 }

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

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

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

References spline(), and splint().

00349 {
00350 
00351         float x0= x[0];
00352         float x1= x[1];
00353         float x2= x[2];
00354         float y0= y[0];
00355         float y1= y[1];
00356         float y2= y[2];
00357         float yp1 =  (y1-y0)/(x1-x0) +  (y2-y0)/(x2-x0) - (y2-y1)/(x2-x1)  ;
00358         float xn  = x[n];
00359         float xnm1= x[n-1];
00360         float xnm2= x[n-2];
00361         float yn  = y[n];
00362         float ynm1= y[n-1];
00363         float ynm2= y[n-2];
00364         float ypn=  (yn-ynm1)/(xn-xnm1) +  (yn-ynm2)/(xn-xnm2) - (ynm1-ynm2)/(xnm1-xnm2) ;
00365         float *y2d = new float[n];
00366         Util::spline(x,y,n,yp1,ypn,y2d);
00367         Util::splint(x,y,y2d,n,xq,yq,m); //PRB
00368         delete [] y2d;
00369         return;
00370 }

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

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

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

References b.

00409 {
00410         int klo, khi, k;
00411         float h, b, a;
00412 
00413 //      klo=0; // can try to put here
00414         for (int j=0; j<m;j++){
00415                 klo=0;
00416                 khi=n-1;
00417                 while (khi-klo >1) {
00418                         k=(khi+klo) >>1;
00419                         if  (xa[k]>xq[j]){ khi=k;}
00420                         else { klo=k;}
00421                 }
00422                 h=xa[khi]- xa[klo];
00423                 if (h==0.0) printf("Bad XA input to routine SPLINT \n");
00424                 a =(xa[khi]-xq[j])/h;
00425                 b=(xq[j]-xa[klo])/h;
00426                 yq[j]=a*ya[klo] + b*ya[khi]
00427                         + ((a*a*a-a)*y2a[klo]
00428                              +(b*b*b-b)*y2a[khi]) *(h*h)/6.0f;
00429         }
00430 //      printf("h=%f, a = %f, b=%f, ya[klo]=%f, ya[khi]=%f , yq=%f\n",h, a, b, ya[klo], ya[khi],yq[0]);
00431 }

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

Calculate a number's square.

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

Definition at line 1571 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 1562 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 1553 of file util.h.

Referenced by EMAN::EMData::do_radon(), get_stats_cstyle(), 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 1581 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(), and main().

00248 {
00249         if (!s1 || !s2) {
00250                 throw NullPointerException("Null string");
00251         }
00252 
00253         if (strncmp(s1, s2, strlen(s2)) == 0) {
00254                 return true;
00255         }
00256 
00257         return false;
00258 }

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

Return a lower case version of the argument string.

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

Definition at line 241 of file util.cpp.

Referenced by EMAN::Transform::detect_problem_keys(), EMAN::Symmetry3D::gen_orientations(), EMAN::Dict::get_ci(), EMAN::Transform::get_params(), EMAN::Transform::get_params_inverse(), EMAN::Transform::get_rotation(), EMAN::Symmetry3D::get_symmetries(), EMAN::Dict::has_key_ci(), and EMAN::Transform::set_rotation().

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

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

Definition at line 4508 of file util_sparx.cpp.

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

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

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

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

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

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

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

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

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 get_value_at(), get_xsize(), get_ysize(), get_zsize(), 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 6021 of file util_sparx.cpp.

References phase(), and sqrt().

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

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

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

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

Quadratic interpolation (3D).

Parameters:
r 
s 
t 
fdata 
Returns:
Interpolated value

Definition at line 1904 of file util_sparx.cpp.

01905 {
01906 
01907     const float C2 = 0.5f;    //1.0 / 2.0;
01908     const float C4 = 0.25f;   //1.0 / 4.0;
01909     const float C8 = 0.125f;  //1.0 / 8.0;
01910 
01911     float  RS   = R * S;
01912     float  ST   = S * T;
01913     float  RT   = R * T;
01914     float  RST  = R * ST;
01915 
01916     float  RSQ  = 1-R*R;
01917     float  SSQ  = 1-S*S;
01918     float  TSQ  = 1-T*T;
01919 
01920     float  RM1  = (1-R);
01921     float  SM1  = (1-S);
01922     float  TM1  = (1-T);
01923 
01924     float  RP1  = (1+R);
01925     float  SP1  = (1+S);
01926     float  TP1  = (1+T);
01927 
01928     float triquad =
01929     (-C8) * RST * RM1  * SM1  * TM1 * fdata[0] +
01930         ( C4) * ST  * RSQ  * SM1  * TM1 * fdata[1] +
01931         ( C8) * RST * RP1  * SM1  * TM1 * fdata[2] +
01932         ( C4) * RT  * RM1  * SSQ  * TM1 * fdata[3] +
01933         (-C2) * T   * RSQ  * SSQ  * TM1 * fdata[4] +
01934         (-C4) * RT  * RP1  * SSQ  * TM1 * fdata[5] +
01935         ( C8) * RST * RM1  * SP1  * TM1 * fdata[6] +
01936         (-C4) * ST  * RSQ  * SP1  * TM1 * fdata[7] +
01937         (-C8) * RST * RP1  * SP1  * TM1 * fdata[8] +
01938 //
01939         ( C4) * RS  * RM1  * SM1  * TSQ * fdata[9]  +
01940         (-C2) * S   * RSQ  * SM1  * TSQ * fdata[10] +
01941         (-C4) * RS  * RP1  * SM1  * TSQ * fdata[11] +
01942         (-C2) * R   * RM1  * SSQ  * TSQ * fdata[12] +
01943                       RSQ  * SSQ  * TSQ * fdata[13] +
01944         ( C2) * R   * RP1  * SSQ  * TSQ * fdata[14] +
01945         (-C4) * RS  * RM1  * SP1  * TSQ * fdata[15] +
01946         ( C2) * S   * RSQ  * SP1  * TSQ * fdata[16] +
01947         ( C4) * RS  * RP1  * SP1  * TSQ * fdata[17] +
01948  //
01949         ( C8) * RST * RM1  * SM1  * TP1 * fdata[18] +
01950         (-C4) * ST  * RSQ  * SM1  * TP1 * fdata[19] +
01951         (-C8) * RST * RP1  * SM1  * TP1 * fdata[20] +
01952         (-C4) * RT  * RM1  * SSQ  * TP1 * fdata[21] +
01953         ( C2) * T   * RSQ  * SSQ  * TP1 * fdata[22] +
01954         ( C4) * RT  * RP1  * SSQ  * TP1 * fdata[23] +
01955         (-C8) * RST * RM1  * SP1  * TP1 * fdata[24] +
01956         ( C4) * ST  * RSQ  * SP1  * TP1 * fdata[25] +
01957         ( C8) * RST * RP1  * SP1  * TP1 * fdata[26]   ;
01958      return triquad;
01959 }

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

Definition at line 7773 of file util_sparx.cpp.

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

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

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

Definition at line 18487 of file util_sparx.cpp.

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

18487                                                                                                              {
18488 
18489         EMData *rot;
18490 
18491         const int nmax=3, mmax=3;
18492         char task[60], csave[60];
18493         long int lsave[4];
18494         long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
18495         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];
18496         long int SIXTY=60;
18497 
18498         //     We wish to have no output.
18499         iprint = -1;
18500 
18501         //c     We specify the tolerances in the stopping criteria.
18502         factr=1.0e1;
18503         pgtol=1.0e-5;
18504 
18505         //     We specify the dimension n of the sample problem and the number
18506         //        m of limited memory corrections stored.  (n and m should not
18507         //        exceed the limits nmax and mmax respectively.)
18508         n=3;
18509         m=3;
18510 
18511         //     We now provide nbd which defines the bounds on the variables:
18512         //                    l   specifies the lower bounds,
18513         //                    u   specifies the upper bounds.
18514         //                    x   specifies the initial guess
18515         x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0;
18516         x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5;
18517         x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5;
18518 
18519 
18520         //     We start the iteration by initializing task.
18521         // (**MUST clear remaining chars in task with spaces (else crash)!**)
18522         strcpy(task,"START");
18523         for (int i=5;i<60;i++)  task[i]=' ';
18524 
18525         //     This is the call to the L-BFGS-B code.
18526         // (* call the L-BFGS-B routine with task='START' once before loop *)
18527         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18528         //int step = 1;
18529 
18530         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
18531         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
18532 
18533                 if (strncmp(task,"FG",2)==0) {
18534                 //   the minimization routine has returned to request the
18535                 //   function f and gradient g values at the current x
18536 
18537                 //        Compute function value f for the sample problem.
18538                 rot = new EMData();
18539                 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2], 1.0f);
18540                 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18541                 //f = -f;
18542                 delete rot;
18543 
18544                 //        Compute gradient g for the sample problem.
18545                 float dt = 1.0e-3f;
18546                 rot = new EMData();
18547                 rot = image->rot_scale_trans2D((float)x[0]+dt, (float)x[1], (float)x[2], 1.0f);
18548                 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18549                 //f1 = -f1;
18550                 g[0] = (f1-f)/dt;
18551                 delete rot;
18552 
18553                 dt = 1.0e-2f;
18554                 rot = new EMData();
18555                 rot = image->rot_scale_trans2D((float)x[0], (float)x[1]+dt, (float)x[2], 1.0f);
18556                 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18557                 //f2 = -f2;
18558                 g[1] = (f2-f)/dt;
18559                 delete rot;
18560 
18561                 rot = new EMData();
18562                 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2]+dt, 1.0f);
18563                 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18564                 //f3 = -f3;
18565                 g[2] = (f3-f)/dt;
18566                 delete rot;
18567                 }
18568 
18569                 //c          go back to the minimization routine.
18570                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18571                 //step++;
18572         }
18573 
18574         //printf("Total step is %d\n", step);
18575         vector<float> res;
18576         res.push_back(static_cast<float>(x[0]));
18577         res.push_back(static_cast<float>(x[1]));
18578         res.push_back(static_cast<float>(x[2]));
18579         //res.push_back(step);
18580         return res;
18581 }

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

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

18583                                                                                                                                      {
18584 
18585         EMData *rot;
18586 
18587         const int nmax=3, mmax=3;
18588         char task[60], csave[60];
18589         long int lsave[4];
18590         long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
18591         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];
18592         long int SIXTY=60;
18593 
18594         //     We wish to have no output.
18595         iprint = -1;
18596 
18597         //c     We specify the tolerances in the stopping criteria.
18598         factr=1.0e1;
18599         pgtol=1.0e-5;
18600 
18601         //     We specify the dimension n of the sample problem and the number
18602         //        m of limited memory corrections stored.  (n and m should not
18603         //        exceed the limits nmax and mmax respectively.)
18604         n=3;
18605         m=3;
18606 
18607         //     We now provide nbd which defines the bounds on the variables:
18608         //                    l   specifies the lower bounds,
18609         //                    u   specifies the upper bounds.
18610         //                    x   specifies the initial guess
18611         x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0;
18612         x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5;
18613         x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5;
18614 
18615 
18616         //     We start the iteration by initializing task.
18617         // (**MUST clear remaining chars in task with spaces (else crash)!**)
18618         strcpy(task,"START");
18619         for (int i=5;i<60;i++)  task[i]=' ';
18620 
18621         //     This is the call to the L-BFGS-B code.
18622         // (* call the L-BFGS-B routine with task='START' once before loop *)
18623         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18624         //int step = 1;
18625 
18626         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
18627         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
18628 
18629                 if (strncmp(task,"FG",2)==0) {
18630                 //   the minimization routine has returned to request the
18631                 //   function f and gradient g values at the current x
18632 
18633                 //        Compute function value f for the sample problem.
18634                 rot = new EMData();
18635                 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2], kb, 1.0f);
18636                 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18637                 //f = -f;
18638                 delete rot;
18639 
18640                 //        Compute gradient g for the sample problem.
18641                 float dt = 1.0e-3f;
18642                 rot = new EMData();
18643                 rot = image->rot_scale_conv7((float)((x[0]+dt)*pi/180), (float)x[1], (float)x[2], kb, 1.0f);
18644                 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18645                 //f1 = -f1;
18646                 g[0] = (f1-f)/dt;
18647                 delete rot;
18648 
18649                 rot = new EMData();
18650                 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1]+dt, (float)x[2], kb, 1.0);
18651                 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18652                 //f2 = -f2;
18653                 g[1] = (f2-f)/dt;
18654                 delete rot;
18655 
18656                 rot = new EMData();
18657                 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2]+dt, kb, 1.0f);
18658                 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18659                 //f3 = -f3;
18660                 g[2] = (f3-f)/dt;
18661                 delete rot;
18662                 }
18663 
18664                 //c          go back to the minimization routine.
18665                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18666                 //step++;
18667         }
18668 
18669         //printf("Total step is %d\n", step);
18670         vector<float> res;
18671         res.push_back(static_cast<float>(x[0]));
18672         res.push_back(static_cast<float>(x[1]));
18673         res.push_back(static_cast<float>(x[2]));
18674         //res.push_back(step);
18675         return res;
18676 }

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

Definition at line 18835 of file util_sparx.cpp.

References ccc_images(), and Steepda().

18835                                                                                                                 {
18836 
18837         double  x[4];
18838         int n;
18839         int l = 3;
18840         int m = 200;
18841         double e = 1e-9;
18842         double step = 0.01;
18843         float (*my_func)(EMData* , EMData* , EMData* , float , float , float) = ccc_images;
18844 
18845         x[1] = ang;
18846         x[2] = sxs;
18847         x[3] = sys;
18848 
18849         Steepda(x, step, e, l, m, &n, my_func, image, refim, mask);   // Call steepest descent optimization subroutine
18850         //printf("Took %d steps\n", n);
18851 
18852         vector<float> res;
18853         res.push_back(static_cast<float>(x[1]));
18854         res.push_back(static_cast<float>(x[2]));
18855         res.push_back(static_cast<float>(x[3]));
18856         res.push_back(static_cast<float>(n));
18857         return res;
18858 }

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

References ccc_images_G(), and Steepda_G().

18872                                                                                                                                         {
18873 
18874         double  x[4];
18875         int n;
18876         int l = 3;
18877         int m = 200;
18878         double e = 1e-9;
18879         double step = 0.001;
18880         float (*my_func)(EMData* , EMData* , EMData* , Util::KaiserBessel&, float , float , float) = ccc_images_G;
18881 
18882         x[1] = ang;
18883         x[2] = sxs;
18884         x[3] = sys;
18885 
18886         Steepda_G(x, step, e, l, m, &n, my_func, image, refim, mask, kb);   // Call steepest descent optimization subroutine
18887         //printf("Took %d steps\n", n);
18888 
18889         vector<float> res;
18890         res.push_back(static_cast<float>(x[1]));
18891         res.push_back(static_cast<float>(x[2]));
18892         res.push_back(static_cast<float>(x[3]));
18893         res.push_back(static_cast<float>(n));
18894         return res;
18895 }

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

References EMAN::EMData::center_origin_fft(), EMAN::EMData::cmp(), EMAN::EMData::do_ift_inplace(), dt, EMAN::EMData::extract_plane(), EMAN::EMData::fft_shuffle(), EMAN::EMData::get_ysize(), EMAN::EMData::process_inplace(), proj, setulb_(), SIXTY, and EMAN::EMData::window_center().

18678                                                                                                                                                             {
18679 
18680         EMData *proj, *proj2;
18681 
18682         const int nmax=5, mmax=5;
18683         char task[60], csave[60];
18684         long int lsave[4];
18685         long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
18686         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];
18687         long int SIXTY=60;
18688 
18689         //     We wish to have no output.
18690         iprint = -1;
18691 
18692         //c     We specify the tolerances in the stopping criteria.
18693         factr=1.0e1;
18694         pgtol=1.0e-5;
18695 
18696         //     We specify the dimension n of the sample problem and the number
18697         //        m of limited memory corrections stored.  (n and m should not
18698         //        exceed the limits nmax and mmax respectively.)
18699         n=5;
18700         m=5;
18701 
18702         //     We now provide nbd which defines the bounds on the variables:
18703         //                    l   specifies the lower bounds,
18704         //                    u   specifies the upper bounds.
18705         //                    x   specifies the initial guess
18706         x[0] = phi;     nbd[0] = 2;     l[0] = phi-2.0;         u[0] = phi+2.0;
18707         x[1] = theta;   nbd[1] = 2;     l[1] = theta-2.0;       u[1] = theta+2.0;
18708         x[2] = psi;     nbd[2] = 2;     l[2] = psi-2.0;         u[2] = psi+2.0;
18709         x[3] = sxs;     nbd[3] = 2;     l[3] = sxs-2.0;         u[3] = sxs+2.0;
18710         x[4] = sys;     nbd[4] = 2;     l[4] = sys-2.0;         u[4] = sys+2.0;
18711 
18712 
18713         //     We start the iteration by initializing task.
18714         // (**MUST clear remaining chars in task with spaces (else crash)!**)
18715         strcpy(task,"START");
18716         for (int i=5;i<60;i++)  task[i]=' ';
18717 
18718         //     This is the call to the L-BFGS-B code.
18719         // (* call the L-BFGS-B routine with task='START' once before loop *)
18720         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18721         int step = 1;
18722 
18723         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
18724         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
18725 
18726                 if (strncmp(task,"FG",2)==0) {
18727                 //   the minimization routine has returned to request the
18728                 //   function f and gradient g values at the current x
18729 
18730                 //        Compute function value f for the sample problem.
18731                 proj = new EMData();
18732                 proj2 = new EMData();
18733                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
18734                 proj->fft_shuffle();
18735                 proj->center_origin_fft();
18736                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
18737                 proj->do_ift_inplace();
18738                 int M = proj->get_ysize()/2;
18739                 proj2 = proj->window_center(M);
18740                 f = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18741                 //f = -f;
18742                 delete proj;
18743                 delete proj2;
18744 
18745                 //        Compute gradient g for the sample problem.
18746                 float dt = 1.0e-3f;
18747                 proj = new EMData();
18748                 proj2 = new EMData();
18749                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0]+dt, "theta", (float)x[1], "psi", (float)x[2])), kb);
18750                 proj->fft_shuffle();
18751                 proj->center_origin_fft();
18752                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
18753                 proj->do_ift_inplace();
18754                 proj2 = proj->window_center(M);
18755                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18756                 //ft = -ft;
18757                 delete proj;
18758                 delete proj2;
18759                 g[0] = (ft-f)/dt;
18760 
18761                 proj = new EMData();
18762                 proj2 = new EMData();
18763                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1]+dt, "psi", (float)x[2])), kb);
18764                 proj->fft_shuffle();
18765                 proj->center_origin_fft();
18766                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
18767                 proj->do_ift_inplace();
18768                 proj2 = proj->window_center(M);
18769                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18770                 //ft = -ft;
18771                 delete proj;
18772                 delete proj2;
18773                 g[1] = (ft-f)/dt;
18774 
18775                 proj = new EMData();
18776                 proj2 = new EMData();
18777                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2]+dt)), kb);
18778                 proj->fft_shuffle();
18779                 proj->center_origin_fft();
18780                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
18781                 proj->do_ift_inplace();
18782                 proj2 = proj->window_center(M);
18783                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18784                 //ft = -ft;
18785                 delete proj;
18786                 delete proj2;
18787                 g[2] = (ft-f)/dt;
18788 
18789                 proj = new EMData();
18790                 proj2 = new EMData();
18791                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
18792                 proj->fft_shuffle();
18793                 proj->center_origin_fft();
18794                 proj->process_inplace("filter.shift", Dict("x_shift", x[3]+dt, "y_shift", x[4], "z_shift", 0.0f));
18795                 proj->do_ift_inplace();
18796                 proj2 = proj->window_center(M);
18797                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18798                 //ft = -ft;
18799                 delete proj;
18800                 delete proj2;
18801                 g[3] = (ft-f)/dt;
18802 
18803                 proj = new EMData();
18804                 proj2 = new EMData();
18805                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
18806                 proj->fft_shuffle();
18807                 proj->center_origin_fft();
18808                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4]+dt, "z_shift", 0.0f));
18809                 proj->do_ift_inplace();
18810                 proj2 = proj->window_center(M);
18811                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
18812                 //ft = -ft;
18813                 delete proj;
18814                 delete proj2;
18815                 g[4] = (ft-f)/dt;
18816                 }
18817 
18818                 //c          go back to the minimization routine.
18819                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18820                 step++;
18821         }
18822 
18823         //printf("Total step is %d\n", step);
18824         vector<float> res;
18825         res.push_back(static_cast<float>(x[0]));
18826         res.push_back(static_cast<float>(x[1]));
18827         res.push_back(static_cast<float>(x[2]));
18828         res.push_back(static_cast<float>(x[3]));
18829         res.push_back(static_cast<float>(x[4]));
18830         //res.push_back(step);
18831         return res;
18832 }

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

References C, ENTERFUNC, EXITFUNC, pi, real2FH(), set_complex(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), set_ri(), EMAN::EMData::set_ri(), EMAN::EMData::set_shuffled(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::to_zero(), update(), EMAN::EMData::update(), x, and y.

00236 {
00237         ENTERFUNC;
00238         int Mid= (Size+1)/2;
00239 
00240         if (flag==0) { // This is the real function
00241                 EMData* ImBW = new EMData();
00242                 ImBW->set_size(Size,Size,1);
00243                 ImBW->to_zero();
00244 
00245                 float tempIm;
00246                 float x,y;
00247 
00248                 for (int ix=(1-Mid);  ix<Mid; ix++){
00249                         for (int iy=(1-Mid);  iy<Mid; iy++){
00250                                 x = (float)ix;
00251                                 y = (float)iy;
00252                         tempIm= static_cast<float>( (1/(2*M_PI)) * cos(p*x)* cos(q*y) * exp(-.5*x*x/(a*a))* exp(-.5*y*y/(b*b)) );
00253                                 (*ImBW)(ix+Mid-1,iy+Mid-1) = tempIm * exp(.5f*p*p*a*a)* exp(.5f*q*q*b*b);
00254                         }
00255                 }
00256                 ImBW->update();
00257                 ImBW->set_complex(false);
00258                 ImBW->set_ri(true);
00259 
00260                 return ImBW;
00261         }
00262         else if (flag==1) {  // This is the Fourier Transform
00263                 EMData* ImBWFFT = new EMData();
00264                 ImBWFFT ->set_size(2*Size,Size,1);
00265                 ImBWFFT ->to_zero();
00266 
00267                 float r,s;
00268 
00269                 for (int ir=(1-Mid);  ir<Mid; ir++){
00270                         for (int is=(1-Mid);  is<Mid; is++){
00271                                 r = (float)ir;
00272                                 s = (float)is;
00273                         (*ImBWFFT)(2*(ir+Mid-1),is+Mid-1)= cosh(p*r*a*a) * cosh(q*s*b*b) *
00274                                 exp(-.5f*r*r*a*a)* exp(-.5f*s*s*b*b);
00275                         }
00276                 }
00277                 ImBWFFT->update();
00278                 ImBWFFT->set_complex(true);
00279                 ImBWFFT->set_ri(true);
00280                 ImBWFFT->set_shuffled(true);
00281                 ImBWFFT->set_fftodd(true);
00282 
00283                 return ImBWFFT;
00284         }
00285         else if (flag==2 || flag==3) { //   This is the projection in Real Space
00286                 float alpha = static_cast<float>( alphaDeg*M_PI/180.0 );
00287                 float C=cos(alpha);
00288                 float S=sin(alpha);
00289                 float D= sqrt(S*S*b*b + C*C*a*a);
00290                 //float D2 = D*D;   PAP - to get rid of warning
00291 
00292                 float P = p * C *a*a/D ;
00293                 float Q = q * S *b*b/D ;
00294 
00295                 if (flag==2) {
00296                         EMData* pofalpha = new EMData();
00297                         pofalpha ->set_size(Size,1,1);
00298                         pofalpha ->to_zero();
00299 
00300                         float Norm0 =  D*(float)sqrt(2*pi);
00301                         float Norm1 =  exp( .5f*(P+Q)*(P+Q)) / Norm0 ;
00302                         float Norm2 =  exp( .5f*(P-Q)*(P-Q)) / Norm0 ;
00303                         float sD;
00304 
00305                         for (int is=(1-Mid);  is<Mid; is++){
00306                                 sD = is/D ;
00307                                 (*pofalpha)(is+Mid-1) =  Norm1 * exp(-.5f*sD*sD)*cos(sD*(P+Q))
00308                          + Norm2 * exp(-.5f*sD*sD)*cos(sD*(P-Q));
00309                         }
00310                         pofalpha-> update();
00311                         pofalpha-> set_complex(false);
00312                         pofalpha-> set_ri(true);
00313 
00314                         return pofalpha;
00315                 }
00316                 if (flag==3) { // This is the projection in Fourier Space
00317                         float vD;
00318 
00319                         EMData* pofalphak = new EMData();
00320                         pofalphak ->set_size(2*Size,1,1);
00321                         pofalphak ->to_zero();
00322 
00323                         for (int iv=(1-Mid);  iv<Mid; iv++){
00324                                 vD = iv*D ;
00325                                 (*pofalphak)(2*(iv+Mid-1)) =  exp(-.5f*vD*vD)*(cosh(vD*(P+Q)) + cosh(vD*(P-Q)) );
00326                         }
00327                         pofalphak-> update();
00328                         pofalphak-> set_complex(false);
00329                         pofalphak-> set_ri(true);
00330 
00331                         return pofalphak;
00332                 }
00333         }
00334         else if (flag==4) {
00335                 cout <<" FH under construction";
00336                 EMData* OutFT= TwoDTestFunc(Size, p, q, a, b, 1);
00337                 EMData* TryFH= OutFT -> real2FH(4.0);
00338                 return TryFH;
00339         } else {
00340                 cout <<" flag must be 0,1,2,3, or 4";
00341         }
00342 
00343         EXITFUNC;
00344         return 0;
00345 }

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

Definition at line 4466 of file util_sparx.cpp.

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

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

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

Definition at line 19593 of file util_sparx.cpp.

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

19593                                     {
19594         const float step=0.001f;
19595         int ny = d->get_ysize();
19596         //  input emdata should have size 2xN, where N is number of points
19597         //  output vector should be 2xN, first element is the number of elements
19598         //  associated with this point, second is 0 is the element is touching the border, 1 if it is interior
19599         vector<float> group(2*ny);
19600         for(int i=0; i<2*ny; i++) group[i] = 0.0f;
19601         int K = int(1.0f/step) +1;
19602         int hit = 0;
19603         for(int kx=0; kx<=K; kx++) {
19604                 float tx = kx*step;
19605                 for(int ky=0; ky<=K; ky++) {
19606                         float ty = ky*step;
19607                         float dm = 1.0e23f;
19608                         for(int i=0; i<ny; i++) {
19609                                 float qd = pow(tx-(*d)(0,i),2) + pow(ty-(*d)(1,i),2);
19610                                 if( qd < dm) {
19611                                         dm = qd;
19612                                         hit = i;
19613                                 }
19614                         }
19615                         data(0,hit) += 1.0f;
19616                         if(kx == 0 || ky == 0 || kx == K || ky == K)  data(1,hit) = 1.0f;
19617                 }
19618         }
19619         return  group;
19620 }

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

Definition at line 7483 of file util_sparx.cpp.

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

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

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

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

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

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

Definition at line 5218 of file util_sparx.cpp.

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

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

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

Definition at line 5706 of file util_sparx.cpp.

References EMAN::EMData::depad(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), max, min, EMAN::EMData::norm_pad(), PROJ, q, EMAN::EMData::set_size(), SS, EMAN::EMData::to_zero(), EMAN::EMData::update(), W, and Y.

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

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

Definition at line 5900 of file util_sparx.cpp.

References AMAX1, AMIN1, CC, CP, EMAN::EMData::depad(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::norm_pad(), PROJ, RI, EMAN::EMData::set_size(), sqrt(), SS, EMAN::EMData::to_one(), EMAN::EMData::update(), VP, VV, and W.

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


The documentation for this class was generated from the following files:
Generated on Mon Jul 19 13:08:06 2010 for EMAN2 by  doxygen 1.4.4