static void cellarray( double xmin, double xmax, double ymin, double ymax, int dx, int dy, int dimx, int *colia, int true_color) { double x1, y1, x2, y2; int ix1, ix2, iy1, iy2; int x, y, width, height; register int i, j, ix, iy, ind; int swapx, swapy; RGBColor color; int rgb, red, green, blue; WC_to_NDC(xmin, ymax, gkss->cntnr, x1, y1); seg_xform(&x1, &y1); NDC_to_DC(x1, y1, ix1, iy1); WC_to_NDC(xmax, ymin, gkss->cntnr, x2, y2); seg_xform(&x2, &y2); NDC_to_DC(x2, y2, ix2, iy2); width = abs(ix2 - ix1) + 1; height = abs(iy2 - iy1) + 1; x = min(ix1, ix2); y = min(iy1, iy2); swapx = ix1 > ix2; swapy = iy1 < iy2; for (j = 0; j < height; j++) { iy = dy * j / height; if (swapy) iy = dy - 1 - iy; for (i = 0; i < width; i++) { ix = dx * i / width; if (swapx) ix = dx - 1 - ix; if (!true_color) { ind = colia[iy * dimx + ix]; color.red = p->rgb[ind].red; color.green = p->rgb[ind].green; color.blue = p->rgb[ind].blue; } else { rgb = colia[iy * dimx + ix]; red = (rgb & 0xff); green = (rgb & 0xff00) >> 8; blue = (rgb & 0xff0000) >> 16; color.red = nint(red * 256); color.green = nint(green * 256); color.blue = nint(blue * 256); } SetCPixel(x + i, y + j, &color); } } }
static float compute_overlap(MRI *mri_seg1, MRI *mri_seg2, TRANSFORM *transform1, TRANSFORM *transform2) { int x, y, z, width, height, depth, l1, l2, x2, y2, z2 ; float overlap, x1, y1, z1 ; TransformInvert(transform1, mri_seg1) ; width = mri_seg1->width ; height = mri_seg1->height ; depth = mri_seg1->depth ; for (overlap = 0.0f, x = 0 ; x < width ; x++) { for (y = 0 ; y < height ; y++) { for (z = 0 ; z < depth ; z++) { l1 = MRIvox(mri_seg1, x, y, z) ; TransformSample(transform1, x, y, z, &x1, &y1, &z1) ; /* atlas coords of s1 */ TransformSampleInverseVoxel(transform2, width, height, depth, nint(x1), nint(y1), nint(z1), &x2, &y2, &z2) ; l2 = MRIvox(mri_seg2, x2, y2, z2) ; if (l1 == l2) overlap++ ; } } } return(overlap) ; }
static void resize_window(void) { double max_width, max_height; int width, height; Rect wRect; max_width = MWIDTH; max_height = max_width * p->sheight / p->swidth; gks_fit_ws_viewport(p->viewport, max_width, max_height, 0.075); width = nint((p->viewport[1] - p->viewport[0]) / max_width * p->swidth); height = nint((p->viewport[3] - p->viewport[2]) / max_height * p->sheight); if (p->width != width || p->height != height) { p->width = width; p->height = height; SizeWindow(p->win, width, height, TRUE); GetWindowPortBounds(p->win, &wRect); ClipRect(&wRect); } }
static void set_font(int font) { double rad, scale, ux, uy; int family, size, angle; double width, height, capheight; StyleParameter face; Str255 name; font = abs(font); if (font >= 101 && font <= 129) font -= 100; else if (font >= 1 && font <= 32) font = map[font - 1]; else font = 9; WC_to_NDC_rel(gkss->chup[0], gkss->chup[1], gkss->cntnr, ux, uy); seg_xform_rel(&ux, &uy); rad = -atan2(ux, uy); angle = (int)(rad * 180 / M_PI + 0.5); if (angle < 0) angle += 360; p->path = ((angle + 45) / 90) % 4; scale = sqrt(gkss->chup[0] * gkss->chup[0] + gkss->chup[1] * gkss->chup[1]); ux = gkss->chup[0] / scale * gkss->chh; uy = gkss->chup[1] / scale * gkss->chh; WC_to_NDC_rel(ux, uy, gkss->cntnr, ux, uy); width = 0; height = sqrt(ux * ux + uy * uy); seg_xform_rel(&width, &height); height = sqrt(width * width + height * height); capheight = nint(height * (fabs(p->c) + 1)); p->capheight = nint(capheight); size = nint(capheight / capheights[font - 1]); if (font > 13) font += 3; p->family = (font - 1) / 4; face = (font % 4 == 1 || font % 4 == 2) ? normal : bold; if (font % 4 == 2 || font % 4 == 0) face |= italic; CopyCStringToPascal(fonts[p->family], name); family = FMGetFontFamilyFromName(name); if (family != kInvalidFontFamily) { TextFont(family); TextFace(face); TextSize(size); } else gks_perror("invalid font family (%s)", fonts[p->family]); }
/*------------------------------------------------------------------------ * move_pu - move pen up function. * * input: lat, lon - beginning of a new segment * * result: previous segment is written, a new segment index entry is started, * and the map is recentered. * * return: FALSE on success * TRUE if fatal error occurs (unabel to allocate enough memory) *------------------------------------------------------------------------*/ int move_pu(double lat, double lon) { double nlon; /* * write current segment */ if (dest->npoints > 0) write_segment_data(dest->seg_count); /* * make sure index is big enough */ if (dest->seg_count >= max_index_entries) { max_index_entries += 1000; dest->index = (cdb_index_entry *) realloc(dest->index, sizeof(cdb_index_entry) * max_index_entries); if(NULL == dest->index) { fprintf(stderr,"move_pu: Unable to allocate %d index entries\n", max_index_entries); return -1; } if (verbose) fprintf(stderr,">allocating %d index entries.\n", max_index_entries); } /* * start a new segment */ dest->index[dest->seg_count].ID = dest->seg_count; dest->index[dest->seg_count].ilat0 = nint(lat/CDB_LAT_SCALE); nlon = lon; NORMALIZE(nlon); dest->index[dest->seg_count].ilon0 = nint(nlon/CDB_LON_SCALE); dest->index[dest->seg_count].ilat_max = dest->index[dest->seg_count].ilat0; dest->index[dest->seg_count].ilon_max = dest->index[dest->seg_count].ilon0; dest->index[dest->seg_count].ilat_min = dest->index[dest->seg_count].ilat0; dest->index[dest->seg_count].ilon_min = dest->index[dest->seg_count].ilon0; /* * recenter map */ map->center_lat = lat; map->center_lon = nlon; map->lat0 = lat; map->lon0 = nlon; reinit_mapx(map); dest->npoints = 0; if (very_very_verbose)fprintf(stderr,">>> recentered map to %lf %lf.\n", map->lat0, map->lon0); return 0; }
static void set_color_rep(int color, double red, double green, double blue) { if (color >= 0 && color < MAX_COLOR) { p->rgb[color].red = nint(red * 65535); p->rgb[color].green = nint(green * 65535); p->rgb[color].blue = nint(blue * 65535); } }
void reverse_current_segment() { static double *lat = NULL; static double *lon = NULL; int ipoints; ipoints = dest->npoints + 1; lat = (double *)realloc(lat, ipoints * sizeof(double)); lon = (double *)realloc(lon, ipoints * sizeof(double)); if(NULL == lat || NULL == lon) { fprintf(stderr,"reverse_current_segment: Unable to allocate %d points for segment %d\n", ipoints, dest->index[dest->seg_count].ID); return; } if(very_verbose) fprintf(stderr, ">> Reversing current segment (%d).\n", dest->index[dest->seg_count].ID); lat[0] = (double) dest->index[dest->seg_count].ilat0 * CDB_LAT_SCALE; lon[0] = (double) dest->index[dest->seg_count].ilon0 * CDB_LON_SCALE; /* * Load true lat/lon for all segment points */ for(ipoints = 0; ipoints < dest->npoints; ipoints++) { lat[ipoints + 1] = lat[ipoints] + (double) dest->data_buffer[ipoints].dlat * CDB_LAT_SCALE; lon[ipoints + 1] = lon[ipoints] + (double) dest->data_buffer[ipoints].dlon * CDB_LON_SCALE; } /* * Read segment data back into current segment in reverse order */ dest->index[dest->seg_count].ilat0 = nint(lat[dest->npoints] / CDB_LAT_SCALE); dest->index[dest->seg_count].ilon0 = nint(lon[dest->npoints] / CDB_LON_SCALE); for(ipoints = dest->npoints - 1, dest->npoints = 0; ipoints >= 0; ipoints--) { draw_pd(lat[ipoints], lon[ipoints]); } return; }
/* figure out what to do with voxels that were turned 'off' by the topology correction. This is a hack, but for now just make them the most likely of the nbr voxel labels. */ static int resegment_erased_voxels(MRI *mri_T1, MRI *mri_in, MRI *mri_out, int target_label) { int x, y, z, label_in, label_out, xi, yi, zi, xk, yk, zk, label, changed=0 ; HISTOGRAM *histos[MAX_CMA_LABEL+1] ; double p, max_p, val ; build_label_histograms(mri_in, mri_T1, histos) ; for (x = 0 ; x < mri_in->width ; x++) { for (y = 0 ; y < mri_in->height ; y++) { for (z = 0 ; z < mri_in->depth ; z++) { label_in = nint(MRIgetVoxVal(mri_in, x, y, z, 0)) ; label_out = nint(MRIgetVoxVal(mri_out, x, y, z, 0)) ; if (label_in == target_label) { // find most likely nbr label max_p = 0 ; label_out = label_in ; for (xk = -1 ; xk <= 1 ; xk++) { xi = x + xk ; if (xi < 0 || xi >= mri_in->width) continue ; for (yk = -1 ; yk <= 1 ; yk++) { yi = y + yk ; if (yi < 0 || yi >= mri_in->height) continue ; for (zk = -1 ; zk <= 1 ; zk++) { zi = z + zk ; if (zi < 0 || zi >= mri_in->depth) continue ; label = nint(MRIgetVoxVal(mri_in, xi, yi, zi, 0)) ; if (label == label_in) continue ; // would be topologically incorrect val = MRIgetVoxVal(mri_T1, xi, yi, zi, 0) ; p = HISTOvalToCount(histos[label], val) ; if (p > max_p) { max_p = p ; label_out = label ; } } } } changed++ ; MRIsetVoxVal(mri_out, x, y, z, 0, label_out) ; } } } } printf("%d voxels resegmented to be ML\n", changed) ; return(NO_ERROR) ; }
static MRI * compute_residuals(MRI *mri_flash, MRI *mri_T1, MRI *mri_PD) { MRI *mri_res ; int x, y, z, width, depth, height, T1, PD, val ; double prediction, sse ; mri_res = MRIclone(mri_flash, NULL) ; width = mri_PD->width ; height = mri_PD->height ; depth = mri_PD->depth ; for (z = 0 ; z < depth ; z++) { for (y = 0 ; y < height ; y++) { for (x = 0 ; x < width ; x++) { T1 = MRISvox(mri_T1, x, y, z) ; PD = MRISvox(mri_PD, x, y, z) ; prediction = FLASHforwardModel(mri_flash->flip_angle, mri_flash->tr, PD, T1) ; val = MRISvox(mri_flash, x, y, z) ; sse = val - prediction ; sse *= sse ; MRISvox(mri_res, x, y, z) = (short)nint(sse) ; } } } return(mri_res) ; }
static float trans_per_buf (float Rbuf, float R_minW_nmos, float R_minW_pmos) { /* Returns the number of minimum width transistor area equivalents needed to * * implement this buffer. Assumes a stage ratio of 4, and equal strength * * pull-up and pull-down paths. */ int num_stage, istage; float trans_count, stage_ratio, Rstage; if (Rbuf > 0.6 * R_minW_nmos || Rbuf <= 0.) { /* Use a single-stage buffer */ trans_count = trans_per_R (Rbuf, R_minW_nmos) + trans_per_R (Rbuf, R_minW_pmos); } else { /* Use a multi-stage buffer */ /* Target stage ratio = 4. 1 minimum width buffer, then num_stage bigger * * ones. */ num_stage = nint (log10 (R_minW_nmos / Rbuf) / log10 (4.)); num_stage = max (num_stage, 1); stage_ratio = pow (R_minW_nmos / Rbuf, 1. / (float) num_stage); Rstage = R_minW_nmos; trans_count = 0.; for (istage=0; istage<=num_stage; istage++) { trans_count += trans_per_R (Rstage, R_minW_nmos) + trans_per_R (Rstage, R_minW_pmos); Rstage /= stage_ratio; } } return (trans_count); }
void HGU_XmSetSliderValue(Widget slider, float value) { Widget scale, text; XmScaleCallbackStruct cbs; short points; int min, max; HGU_XmSliderFunc func; if( (scale = XtNameToWidget(slider, ".scale")) == NULL ) return; if( (text = XtNameToWidget(slider, ".text")) == NULL ) return; XtVaGetValues(scale, XmNdecimalPoints, &points, XmNminimum, &min, XmNmaximum, &max, XmNuserData, &func, NULL); while( points-- > 0 ) value *= 10.0; if( func != NULL ) value = min + (max - min) * (*func)((float) (value - min) / (max - min), 1); cbs.reason = XmCR_VALUE_CHANGED; cbs.event = NULL; cbs.value = nint((double) value); XtVaSetValues(scale, XmNvalue, cbs.value, NULL); update_slider_text(scale, text, &cbs); return; }
static MRI * MRIcomputePriors(MRI *mri_priors, int ndof, MRI *mri_char_priors) { int width, height, depth, x, y, z ; BUFTYPE *pchar_prior, char_prior ; float *pprior, prior ; width = mri_priors->width ; height = mri_priors->height ; depth = mri_priors->depth ; if (!mri_char_priors) { mri_char_priors = MRIalloc(width, height, depth, MRI_UCHAR) ; } for (z = 0 ; z < depth ; z++) { for (y = 0 ; y < height ; y++) { pprior = &MRIFvox(mri_priors, 0, y, z) ; pchar_prior = &MRIvox(mri_char_priors, 0, y, z) ; for (x = 0 ; x < width ; x++) { if (x == DEBUG_X && y == DEBUG_Y && z == DEBUG_Z) DiagBreak() ; prior = *pprior++ ; if (prior > 0) DiagBreak() ; if (prior > 10) DiagBreak() ; char_prior = (BUFTYPE)nint(100.0f*prior/(float)ndof) ; if (char_prior > 101) DiagBreak() ; *pchar_prior++ = char_prior ; } } } return(mri_char_priors) ; }
static int check_volume(MRI *mri_save, MRI *mri_out, int target_label) { int x, y, z, sval, oval ; for (x = 0 ; x < mri_save->width ; x++) for (y = 0 ; y < mri_save->height ; y++) for (z = 0 ; z < mri_save->depth ; z++) { if (x == Gx && y == Gy && z == Gz) DiagBreak() ; sval = nint(MRIgetVoxVal(mri_save, x, y, z, 0)) ; oval = nint(MRIgetVoxVal(mri_out, x, y, z, 0)) ; if ((oval == target_label && sval == 0) || (oval != target_label && sval > 0)) DiagBreak() ; } return(NO_ERROR) ; }
extern MATRIX_T* gen_pam_matrix( ALPH_T alph, /* alphabet */ int dist, /* PAM distance */ BOOLEAN_T logodds /* true: generate log-odds matrix false: generate target frequency matrix */ ) { assert(alph == DNA_ALPH || alph == PROTEIN_ALPH); int i, j; MATRIX_T *matrix, *mul; BOOLEAN_T dna = (alph == DNA_ALPH); double *pfreq = dna ? pam_dna_freq : pam_prot_freq; // standard frequencies int alen = alph_size(alph, ALPH_SIZE); // length of standard alphabet double factor = dist < 170 ? 2/log(2) : 3/log(2); // same as in "pam" Version 1.0.6 /* create the array for the joint probability matrix */ matrix = allocate_matrix(alen, alen); mul = allocate_matrix(alen, alen); /* initialize the matrix: PAM 1: due to roundoff, take the average of the two estimates of the joint frequency of i and j as the joint, then compute the conditionals for the matrix */ for (i=0; i<alen; i++) { for (j=0; j<=i; j++) { double vij = dna ? trans[i][j] : dayhoff[i][j]; double vji = dna ? trans[j][i] : dayhoff[j][i]; double joint = ((vij * pfreq[j]) + (vji * pfreq[i]))/20000;/* use average to fix rndoff */ set_matrix_cell(i, j, joint/pfreq[j], matrix); if (i!=j) set_matrix_cell(j, i, joint/pfreq[i], matrix); } } /* take PAM matrix to desired power to scale it */ copy_matrix(matrix, mul); for (i=dist; i>1; i--) { MATRIX_T *product = matrix_multiply(matrix, mul); SWAP(MATRIX_T*, product, matrix) free_matrix(product); } free_matrix(mul); /* convert to joint or logodds matrix: target: J_ij = Pr(i,j) = Mij pr(j) logodds: L_ij = log (Pr(i,j)/(Pr(i)Pr(j)) = log (Mij Pr(j)/Pr(i)Pr(j)) = log(Mij/pr(i)) */ for (i=0; i<alen; i++) { for (j=0; j<alen; j++) { double vij = get_matrix_cell(i, j, matrix); vij = logodds ? nint(factor * log((vij+EPSILON)/pfreq[i])) : vij * pfreq[j]; set_matrix_cell(i, j, vij, matrix); } } return matrix; } /* gen_pam_matrix */
/* Fairly general interpolation routine to take a function specified on an irregular grid of points defined by x1 and y1 and interpolate them onto a regular grid, y, with a simple linear interpolation formula between (x1,y1) pairs. This algorithm was written with an implicit assumption that x1,y1 pairs were widely spaced compared to dx so this was mainly a fill opertion. I think it will handle vertical discontinuities correctly, but I'm not sure it will deal with a highly oversampled x1,y1 relative to dx. Unpredictable behaviour is guaranteed if the x1,y1 pairs are not in order of increasing x1. arguments: x1 - vector of length n1 of abscissa values of irregular grid to be interpolated. y1 - parallel vector to x1 of function values. n1 - length of x1 and y1 y - output function of regularly sampled values x0 - abscissa value of first sample of y dx - sample interval of y. ny - length of y. Author: Gary Pavlis Written: December 2001 Modified: May 2002 Changed error codes. Now returns an error if elements of y are set. */ int irregular_to_regular_interpolate(double *x1, double *y1, int n1, double *y, double x0, double dx, int ny) { int i1,i; int istart,i1start; double grad; double x; int ny_set=0; /* first zero y*/ for(i=0;i<ny;++i) y[i] = 0.0; /* silently do nothing if n1 is invalid */ if(n1<=0) return(-1); /* find the starting point */ i1start = 0; istart = nint((x1[0]-x0)/dx); if(istart<0) { do { ++i1start; istart = nint((x1[i1start]-x0)/dx); } while (istart<0); } for(i=istart,i1=i1start;i<ny,i1<n1-1;++i1) { if(x1[i1+1]==x1[i1])continue; grad = (y1[i1+1]-y1[i1])/(x1[i1+1]-x1[i1]); x = x0 + dx*((double)i); while((x<=x1[i1+1]) && (i<ny) ) { y[i] = y1[i1] + grad*(x-x1[i1]); ++i; ++ny_set; x += dx; } } if(ny_set<=0) return(-2); else return(0); }
void tdlg::on_tsSpin_editingFinished() { if(bedit[0]) { bedit[0] = false; buser = true; checkval(&Tusr[0], Tmin[0], Tmax[0]); ui->tsSpin->setValue(nint(Tusr[0])); } }
static int cvector_extract_best_avg(float *vbest_avgs, float *vsrc, float *vdst, int navgs, int num) { int i ; for (i = 0 ; i < num ; i++) { if (nint(vbest_avgs[i]) == navgs) vdst[i] = vsrc[i] ; } return(NO_ERROR) ; }
static int extract_thickness_at_best_scale(MRI_SURFACE *mris, float **c1_avg_thickness, float *vbest_avgs, float **c1_thickness, int num, int nvectors) { int i, max_avgs, avgs, n ; for (max_avgs = i = 0 ; i < num ; i++) if (nint(vbest_avgs[i]) >= max_avgs) max_avgs = nint(vbest_avgs[i]) ; for (avgs = 0 ; avgs <= max_avgs ; avgs++) { for (n = 0 ; n < nvectors ; n++) { cvector_extract_best_avg(vbest_avgs, c1_thickness[n], c1_avg_thickness[n], avgs-1, num) ; MRISimportCurvatureVector(mris, c1_thickness[n]) ; MRISaverageCurvatures(mris, 1) ; MRISextractCurvatureVector(mris, c1_thickness[n]) ; } } return(NO_ERROR) ; }
void hms_c( double *deg, fchar convstr, double *coor, fint *prec, fint *output ) { fint l1, l2, n, hour, minut ; double second ; char cstring[MAXTEXTLEN] ; *deg = fmod( (*deg + 360.0), 360.0 ) ; hour = (int) (*deg/15.0) ; minut = (int) ( *deg*4.0-(double)(hour*60) ); minut = abs(minut) ; second = ( ( *deg - (double)(hour*15.0) - (double)(minut/4.0) )*240.0 ) ; second = fabs(second) ; if( coor != NULL ){ coor[0] = (double) hour ; coor[1] = (double) minut ; coor[2] = second ; } if( !*prec && nint(second) == 60 ){ second -= 60.0 ; minut += 1 ; } if( minut == 60 || minut == 61 ){ minut -= 60 ; hour += 1 ; } if( hour == 24 ) hour = 0 ; if( *output == 0 ){ l1 = sprintf( cstring, "%dh %2dm", hour, minut ) ; if( !*prec && second < 0.5 ) l2 = sprintf( cstring, "%s 00s", cstring ) ; else l2 = sprintf( cstring, "%s %*.*fs", cstring, width(*prec), (int)(*prec), second ) ; } else{ l1 = sprintf( cstring, "%d\\uh\\d%2d\\um\\d", hour, minut ) ; if( !*prec && second < 0.5 ) l2 = sprintf( cstring, "%s00\\us\\d", cstring ) ; else l2 = sprintf( cstring, "%s%*.*f\\us\\d", cstring, width(*prec) , (int)(*prec) , second ) ; } for( n = 0 ; n < l2 && n < convstr.l ; n++ )convstr.a[n] = cstring[n] ; for( ; n < convstr.l ; convstr.a[n++] = ' ' ) ; return ; }
static t_type_ptr find_type_col(INP int x) { int i, j; int start, repeat; float rel; boolean match; int priority, num_loc; t_type_ptr column_type; priority = FILL_TYPE->grid_loc_def[0].priority; column_type = FILL_TYPE; for (i = 0; i < num_types; i++) { // EH: Do not ignore IO_TYPE if (/*&type_descriptors[i] == IO_TYPE ||*/ &type_descriptors[i] == EMPTY_TYPE || &type_descriptors[i] == FILL_TYPE) continue; num_loc = type_descriptors[i].num_grid_loc_def; for (j = 0; j < num_loc; j++) { if (priority < type_descriptors[i].grid_loc_def[j].priority) { match = FALSE; if (type_descriptors[i].grid_loc_def[j].grid_loc_type == COL_REPEAT) { start = type_descriptors[i].grid_loc_def[j].start_col; repeat = type_descriptors[i].grid_loc_def[j].repeat; if (start < 0) { start += (nx + 1); } if (x == start) { match = TRUE; } else if (repeat > 0 && x > start && start > 0) { if ((x - start) % repeat == 0) { match = TRUE; } } } else if (type_descriptors[i].grid_loc_def[j].grid_loc_type == COL_REL) { rel = type_descriptors[i].grid_loc_def[j].col_rel; if (nint(rel * nx) == x) { match = TRUE; } } if (match) { priority = type_descriptors[i].grid_loc_def[j].priority; column_type = &type_descriptors[i]; } } } } return column_type; }
std::array<float,4> RadPattern::chiSquare(const RadPattern &rp2, const MA3 &sigmasM, const bool normalizeA) { if( grtM.empty() ) return {NaN, NaN, NaN, NaN}; // normalize the amplitudes of rp2in if requested //RadPattern rp2C; if( normalizeA ) { NormBy(rp2, sigmasM); } //auto &rp2 = normalizeA ? rp2C : rp2in; int n = 0; float chiSG = 0., chiSP = 0., chiSA = 0.; for( auto &pvPair : grtM ) { // check for consistency auto per = pvPair.first; auto size = pvPair.second.size(); auto I2 = rp2.grtM.find(per); if( (I2->first)!=per || (I2->second).size()!=size ) { std::stringstream ss; ss<<"("<<per<<", "<<size<<") - ("<<(I2->first)<<", "<<(I2->second).size()<<")"; throw ErrorRP::HeaderMismatch(FuncName, ss.str()); } // locate group, phase, and amplitude vectors for current period auto grtA1 = pvPair.second.data(); auto grtA2 = I2->second.data(); // group auto phtA1 = phtM.at(per).data(); auto phtA2 = rp2.phtM.at(per).data(); // phase auto ampA1 = ampM.at(per).data(); auto ampA2 = rp2.ampM.at(per).data(); // amplitude // compute rms float rmsG = 0., rmsP = 0., rmsA = 0.; for(int i=0; i<size; i++) { if( grtA1[i]==RadPattern::NaN || grtA2[i]==RadPattern::NaN ) continue; float gdiff = grtA1[i] - grtA2[i]; rmsG += gdiff*gdiff; float pdiff = phtA1[i] - phtA2[i]; pdiff -= nint(pdiff/per)*per; rmsP += pdiff*pdiff; float Adiff = log(ampA1[i]/ampA2[i]); rmsA += Adiff*Adiff; ++n; } // chi square formulas auto &sigmasA = sigmasM.at(per); // get sigmas for the current period float sigmaA = -log(1.-sigmasA[2]); chiSG += rmsG / (sigmasA[0]*sigmasA[0]); chiSP += rmsP / (sigmasA[1]*sigmasA[1]); chiSA += rmsA / (sigmaA*sigmaA); } return std::array<float, 4> {chiSG, chiSP, chiSA, (float)n}; }
int read_golomb_code_am(int b, BFile *bf) { int q, i, nr_sc, lb, ub; unsigned int r; unsigned char bit; double ldb; ldb = log2(b * 1.0); ub = nint(ceil(ldb)); lb = ub - 1; /* read unary part */ q = 0; do { BFread(&bit, 1, bf); if (bit) q++; } while (bit); nr_sc = (1 << ub) - b; /* read binary part, bitwise */ r = 0; for (i = 0; i < lb; i++) { r <<= 1; BFread(&bit, 1, bf); r |= bit; } if (debug_cwb_compress_rdx) fprintf(debug_output, "%8d: Read r=%5d [%3d/%3d] #sc=%4d, ", codepos, r, lb, ub, nr_sc); if (r >= nr_sc) { r <<= 1; BFread(&bit, 1, bf); r |= bit; r -= nr_sc; } if (debug_cwb_compress_rdx) fprintf(debug_output, "final r=%d\tgap=%d\n", r, r+q*b); return r + q * b; }
static int normalize_timepoints_with_samples(MRI *mri, GCA_SAMPLE *gcas, int nsamples, int nsoap) { int frame, i, x, y, z ; double target, val ; MRI *mri_ctrl, *mri_bias, *mri_target, *mri_frame ; mri_ctrl = MRIcloneDifferentType(mri, MRI_UCHAR) ; mri_bias = MRIcloneDifferentType(mri, MRI_FLOAT) ; mri_target = MRIcloneDifferentType(mri, MRI_FLOAT) ; for (i = 0 ; i < nsamples ; i++) { if (i == Gdiag_no) DiagBreak() ; x = nint(gcas[i].x) ; y = nint(gcas[i].y) ; z = nint(gcas[i].z) ; MRIsetVoxVal(mri_ctrl, x, y, z, 0, CONTROL_MARKED) ; for (target = 0.0, frame = 0 ; frame < mri->nframes ; frame++) target += MRIgetVoxVal(mri, x, y, z, frame) ; target /= mri->nframes ; MRIsetVoxVal(mri_target, x, y, z, 0, target) ; } // build a bias correction for each time point (which each has its own frame) for (frame = 0 ; frame < mri->nframes ; frame++) { MRIclear(mri_bias) ; for (i = 0 ; i < nsamples ; i++) { if (i == Gdiag_no) DiagBreak() ; x = nint(gcas[i].x) ; y = nint(gcas[i].y) ; z = nint(gcas[i].z) ; target = MRIgetVoxVal(mri_target, x, y, z, 0) ; val = MRIgetVoxVal(mri, x, y, z, frame) ; if (FZERO(val)) val = 1.0 ; MRIsetVoxVal(mri_bias, x, y, z, 0, target/val) ; } MRIbuildVoronoiDiagram(mri_bias, mri_ctrl, mri_bias) ; MRIsoapBubble(mri_bias, mri_ctrl, mri_bias, nsoap) ; mri_frame = MRIcopyFrame(mri, NULL, frame, 0) ; MRImultiply(mri_frame, mri_bias, mri_frame) ; if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON) { char fname[STRLEN] ; sprintf(fname, "frame%d.mgz", frame) ; MRIwrite(mri_frame, fname) ; sprintf(fname, "bias%d.mgz", frame) ; MRIwrite(mri_bias, fname) ; sprintf(fname, "target%d.mgz", frame) ; MRIwrite(mri_target, fname) ; } MRIcopyFrame(mri_frame, mri, 0, frame) ; } MRIfree(&mri_bias) ; MRIfree(&mri_target) ; MRIfree(&mri_ctrl) ; return(NO_ERROR) ; }
static void polyline(int n, double *px, double *py) { int ln_type, ln_color; double ln_width; int width; ln_type = gkss->asf[0] ? gkss->ltype : gkss->lindex; ln_width = gkss->asf[1] ? gkss->lwidth : 1; ln_color = gkss->asf[2] ? gkss->plcoli : 1; if (gkss->version > 4) width = nint(ln_width * p->height / 500.0); else width = nint(ln_width); if (width < 1) width = 1; PenSize(width, width); set_color(ln_color); gks_set_dev_xform(gkss, p->window, p->viewport); gks_emul_polyline(n, px, py, ln_type, gkss->cntnr, move, draw); }
void write_golomb_code_am(int x, int b, BFile *bf) { int q, res, lb, ub, nr_sc, nr_lc; int r, lr; int i; double ldb; unsigned char bit1 = '\1'; unsigned char bit0 = '\0'; q = x / b; res = x - q * b; ldb = log2(b * 1.0); ub = nint(ceil(ldb)); lb = ub - 1; /* write the unary part q */ for (i = 0; i < q; i++) BFwrite(bit1, 1, bf); BFwrite(bit0, 1, bf); /* write the binary part */ nr_sc = (1 << ub) - b; if (debug_cwb_compress_rdx) fprintf(debug_output, " res=%5d CL [%3d/%3d] #sc %4d " "writing %5d/%d\n", res, lb, ub, nr_sc, (res < nr_sc) ? res : res + nr_sc, (res < nr_sc) ? lb : ub); if (res < nr_sc) { BFwriteWord((unsigned int)res, lb, bf); } else { BFwriteWord((unsigned int)(res + nr_sc), ub, bf); if (res + nr_sc >= (1 << ub)) Rprintf( "Warning: can't encode %d in %d bits\n", res + nr_sc, ub); } }
static int test(MRI *mri1, MRI *mri2, MRI *mri3, MATRIX *m_vol1_to_vol2_ras) { VECTOR *v_test, *v_vox ; float x_ras1, y_ras1, z_ras1, x_ras2, y_ras2, z_ras2, x_vox1, y_vox1, z_vox1, x_vox2, y_vox2, z_vox2 ; MATRIX *m_vol2_vox2ras, *m_vol2_ras2vox, *m_vol1_ras2vox, *m_vol1_vox2ras, *m_vol3_ras2vox, *m_vol3_vox2ras ; int val ; v_test = VectorAlloc(4, MATRIX_REAL) ; m_vol1_vox2ras = MRIgetVoxelToRasXform(mri1) ; m_vol2_vox2ras = MRIgetVoxelToRasXform(mri2) ; m_vol1_ras2vox = MRIgetRasToVoxelXform(mri1) ; m_vol2_ras2vox = MRIgetRasToVoxelXform(mri2) ; m_vol3_vox2ras = MRIgetVoxelToRasXform(mri3) ; m_vol3_ras2vox = MRIgetRasToVoxelXform(mri3) ; x_ras1 = 126.50 ; y_ras1 = -125.500 ; z_ras1 = 127.50 ; V3_X(v_test) = x_ras1 ; V3_Y(v_test) = y_ras1 ; V3_Z(v_test) = z_ras1 ; *MATRIX_RELT(v_test, 4, 1) = 1.0 ; v_vox = MatrixMultiply(m_vol1_ras2vox, v_test, NULL) ; x_vox1 = V3_X(v_vox) ; y_vox1 = V3_Y(v_vox) ; z_vox1 = V3_Z(v_vox) ; val = MRISvox(mri1, nint(x_vox1), nint(y_vox1), nint(z_vox1)) ; printf("VOL1: ras (%1.1f, %1.1f, %1.1f) --> VOX (%1.1f, %1.1f, %1.1f) = %d\n", x_ras1, y_ras1, z_ras1, x_vox1, y_vox1, z_vox1, val) ; x_ras2 = 76.5421 ; y_ras2 = 138.5352 ; z_ras2 = 96.0910 ; V3_X(v_test) = x_ras2 ; V3_Y(v_test) = y_ras2 ; V3_Z(v_test) = z_ras2 ; *MATRIX_RELT(v_test, 4, 1) = 1.0 ; v_vox = MatrixMultiply(m_vol2_ras2vox, v_test, NULL) ; x_vox2 = V3_X(v_vox) ; y_vox2 = V3_Y(v_vox) ; z_vox2 = V3_Z(v_vox) ; val = MRISvox(mri2, nint(x_vox2), nint(y_vox2), nint(z_vox2)) ; printf("VOL2: ras (%2.1f, %2.1f, %2.1f) --> VOX (%2.1f, %2.1f, %2.1f) = %d\n", x_ras2, y_ras2, z_ras2, x_vox2, y_vox2, z_vox2, val) ; MatrixFree(&v_test) ; return(NO_ERROR) ; }
MRI * MRIapplyBayesLaw(MRI *mri_priors, MRI *mri_p1, MRI *mri_p2, MRI *mri_dst) { int x, y, z, width, height, depth ; BUFTYPE *ppriors, *pdst ; float p, p1, p2, prior, *pp1, *pp2 ; if (!mri_dst) mri_dst = MRIclone(mri_priors, NULL) ; width = mri_dst->width ; height = mri_dst->height ; depth = mri_dst->depth ; for (z = 0 ; z < depth ; z++) { for (y = 0 ; y < height ; y++) { ppriors = &MRIvox(mri_priors, 0, y, z) ; pp1 = &MRIFvox(mri_p1, 0, y, z) ; pp2 = &MRIFvox(mri_p2, 0, y, z) ; pdst = &MRIvox(mri_dst, 0, y, z) ; for (x = 0 ; x < width ; x++) { if (DEBUG_POINT(x,y,z)) DiagBreak() ; p1 = (float)*pp1++ ; p2 = (float)*pp2++ ; prior = (float)*ppriors++ ; p1 /= 100.0f ; p2 /= 100.0f ; prior /= 100.0f ; p1 *= prior ; p2 *= (1.0f-prior) ; p = p1 / (p1 + p2); *pdst++ = (BUFTYPE)nint(p*100.0f) ; } } } return(mri_dst) ; }
int main(int argc, char *argv[]) { char **av, fname[STRLEN] ; int ac, nargs, i ; char *in_fname, *out_fname ; int msec, minutes, seconds ; struct timeb start ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: main_template.c,v 1.5 2011/03/02 00:04:40 nicks Exp $", "$Name: $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; TimerStart(&start) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 3) usage_exit(1) ; msec = TimerStop(&start) ; seconds = nint((float)msec/1000.0f) ; minutes = seconds / 60 ; seconds = seconds % 60 ; fprintf(stderr, "inverse operator application took %d minutes" " and %d seconds.\n", minutes, seconds) ; exit(0) ; return(0) ; }
/************************************************************************ * Function: int slider_scale_value() * * Purpose: Calculate the integer value corrsponding to the given * * string and number of decimal points which can be used * * to update the scale position. * * Returns: the value or 0 if scanf fails. * * Arguments: ************************************************************************/ static int slider_scale_value( String stringValue, int points, int min, int max, HGU_XmSliderFunc func) { float value=0.0; int val; sscanf( stringValue, "%f", &value ); while( points-- > 0 ) value *= 10; if( func != NULL ) value = min + (max - min) * (*func)( (float)(value - min)/(max-min), 1 ); val = nint((double) value); return( val ); }
static int build_label_histograms(MRI *mri_labels, MRI *mri_intensities, HISTOGRAM **histos) { int labels[MAX_LABEL+1], x, y, z, l ; MRI *mri_xformed ; MATRIX *m_vox2vox ; memset(labels, 0, sizeof(labels)) ; m_vox2vox = MRIgetVoxelToVoxelXform(mri_intensities, mri_labels) ; mri_xformed = MRIclone(mri_labels, NULL) ; MRIlinearTransform(mri_intensities, mri_xformed, m_vox2vox) ; MatrixFree(&m_vox2vox) ; if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON) MRIwrite(mri_xformed, "x.mgz") ; for (x = 0 ; x < mri_labels->width ; x++) for (y = 0 ; y < mri_labels->height ; y++) for (z = 0 ; z < mri_labels->depth ; z++) { l = nint(MRIgetVoxVal(mri_labels, x, y, z, 0)) ; // if (l == 0) // continue ; if (labels[l] == 0) // first time { char fname[STRLEN] ; histos[l] = MRIhistogramLabel(mri_xformed, mri_labels, l, 50) ; HISTOmakePDF(histos[l], histos[l]) ; sprintf(fname, "label%d.plt", l) ; if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON) HISTOplot(histos[l], fname) ; } labels[l] = 1 ; } MRIfree(&mri_xformed) ; return(NO_ERROR) ; }