/*---------------------------------------------------------------*/ int main(int argc, char *argv[]) { int nargs; nargs = handle_version_option (argc, argv, vcid, "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; cmdline = argv2cmdline(argc,argv); uname(&uts); getcwd(cwd,2000); Progname = argv[0] ; argc --; argv++; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; if (argc == 0) usage_exit(); parse_commandline(argc, argv); check_options(); if (checkoptsonly) return(0); dump_options(stdout); SUBJECTS_DIR = getenv("SUBJECTS_DIR"); if (SUBJECTS_DIR == NULL) { printf("ERROR: SUBJECTS_DIR not defined in environment\n"); exit(1); } return 0; }
int main(int argc, char *argv[]) { char **av, *in_fname, *out_fname ; int ac, nargs ; MRI_SURFACE *mris ; float alpha, beta, gamma ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mris_rotate.c,v 1.6 2011/03/02 00:04:33 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 6) usage_exit() ; in_fname = argv[1] ; if (sscanf(argv[2], "%f", &alpha) != 1) ErrorExit(ERROR_BADPARM, "%s: could not scan alpha from %s", Progname, argv[2]) ; if (sscanf(argv[3], "%f", &beta) != 1) ErrorExit(ERROR_BADPARM, "%s: could not scan beta from %s", Progname, argv[3]) ; if (sscanf(argv[4], "%f", &gamma) != 1) ErrorExit(ERROR_BADPARM, "%s: could not scan gamma from %s", Progname, argv[4]) ; out_fname = argv[5] ; mris = MRISfastRead(in_fname) ; if (!mris) ErrorExit(ERROR_NOFILE, "%s: could not read surface file %s", Progname, in_fname) ; alpha = RADIANS(alpha) ; beta = RADIANS(beta) ; gamma = RADIANS(gamma) ; MRIScenter(mris, mris) ; MRISrotate(mris, mris, alpha, beta, gamma) ; if (!mris) ErrorExit(ERROR_NOFILE, "%s: could not rotate surface", Progname) ; if (Gdiag & DIAG_SHOW) fprintf(stderr, "writing rotated surface to %s\n", out_fname) ; MRISwrite(mris, out_fname) ; exit(0) ; return(0) ; /* for ansi */ }
player_sd_t* player_sd_init(void) { player_sd_t* sd; player_sd_mdns_t* mdns; sd = (player_sd_t*)malloc(sizeof(player_sd_t)); assert(sd); sd->devs = NULL; sd->devs_len = 0; mdns = (player_sd_mdns_t*)malloc(sizeof(player_sd_mdns_t)); assert(mdns); mdns->browseRef_valid = 0; mdns->mdnsDevs = NULL; mdns->mdnsDevs_len = 0; mdns->callb = NULL; mdns->flags = 0; sd->sdRef = mdns; pthread_mutex_init(&(mdns->mutex),NULL); // Initialize the interface table, so that we can decode the interface // strings names that are used in TXT records. itable_init(); // Pick a default debug level ErrorInit(1,NULL); return(sd); }
int main(int argc, char *argv[]) { char **av, *out_vol ; int ac, nargs ; MRI *mri_time1, *mri_time2, *mri_tmp, *mri_atrophy ; TRANSFORM *transform1, *transform2 ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mri_map_atrophy.c,v 1.4 2011/03/02 00:04:22 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 6) usage_exit() ; out_vol = argv[argc-1] ; printf("reading volume from %s...\n", argv[1]) ; mri_time1 = MRIread(argv[1]) ; if (!mri_time1) ErrorExit(ERROR_NOFILE, "%s: could not read MRI volume %s", Progname, argv[2]) ; mri_time2 = MRIread(argv[2]) ; if (!mri_time2) ErrorExit(ERROR_NOFILE, "%s: could not read MRI volume %s", Progname, argv[2]) ; transform1 = TransformRead(argv[3]) ; if (!transform1) ErrorExit(ERROR_NOFILE, "%s: could not read transform from %s", Progname, argv[3]) ; transform2 = TransformRead(argv[4]) ; if (!transform2) ErrorExit(ERROR_NOFILE, "%s: could not read transform from %s", Progname, argv[4]) ; mri_tmp = TransformApplyType(transform1, mri_time1, NULL, SAMPLE_NEAREST); MRIfree(&mri_time1) ; mri_time1 = mri_tmp ; mri_tmp = TransformApplyType(transform2, mri_time2, NULL, SAMPLE_NEAREST); MRIfree(&mri_time2) ; mri_time2 = mri_tmp ; mri_atrophy = make_atrophy_map(mri_time1, mri_time2, NULL, transform1, transform2, gray_labels, ngray, csf_labels, ncsf) ; MRIwrite(mri_atrophy, out_vol) ; exit(0) ; return(0) ; /* for ansi */ }
int main(int argc, char *argv[]) { char **av ; int ac, nargs ; MRI *mri_src, *mri_dst = NULL ; char *in_fname, *out_fname ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mri_polv.c,v 1.6 2011/03/02 00:04:24 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 1) argc = 1 ; if (argc < 1) ErrorExit(ERROR_BADPARM, "%s: no input name specified", Progname) ; in_fname = argv[1] ; if (argc < 2) ErrorExit(ERROR_BADPARM, "%s: no output name specified", Progname) ; out_fname = argv[2] ; if (verbose) fprintf(stderr, "reading from %s...", in_fname) ; mri_src = MRIread(in_fname) ; if (!mri_src) ErrorExit(ERROR_NO_FILE, "%s: could not open source file %s", Progname, in_fname) ; if (verbose) fprintf(stderr, "done.\ncalculating plane of least variance...") ; mri_dst = MRIcentralPlaneOfLeastVarianceNormal(mri_src, NULL, window_size) ; if (!mri_dst) ErrorExit(ERROR_BADPARM, "%s: plane of least variance calculation failed", Progname) ; if (verbose) fprintf(stderr, "\ndone. writing output to %s", out_fname) ; MRIwrite(mri_dst, out_fname) ; if (verbose) fprintf(stderr, "\n") ; exit(0) ; return(0) ; }
int main(int argc, char *argv[]) { char **av ; int ac, nargs ; MRI *mri_src, *mri_dst ; char *in_fname, *out_fname ; int label, nvox ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mri_copy_values.c,v 1.5 2011/03/02 00:04:14 nicks Exp $", "$Name: $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 2) ErrorExit(ERROR_BADPARM, "%s: no input name specified", Progname) ; in_fname = argv[1] ; if (argc < 3) ErrorExit(ERROR_BADPARM, "%s: no value specified", Progname) ; label = atoi(argv[2]) ; if (argc < 4) ErrorExit(ERROR_BADPARM, "%s: no output name specified", Progname) ; out_fname = argv[3] ; fprintf(stderr, "reading from %s...\n", in_fname) ; mri_src = MRIread(in_fname) ; if (!mri_src) ErrorExit(ERROR_NOFILE, "%s: could not read input volume %s", Progname, in_fname) ; mri_dst = MRIread(out_fname) ; if (!mri_dst) ErrorExit(ERROR_NOFILE, "%s: could not read destination volume %s", Progname, out_fname) ; nvox = MRIcopyLabel(mri_src, mri_dst, label) ; fprintf(stderr, "%d voxels copied from input to output volume...\n", nvox); fprintf(stderr, "writing to %s...\n", out_fname) ; MRIwrite(mri_dst, out_fname) ; MRIfree(&mri_dst) ; MRIfree(&mri_src) ; exit(0) ; return(0) ; }
int main(int argc, char *argv[]) { char **av ; int ac, nargs, i ; MRI *mri_src, *mri_dst = NULL ; char *in_fname, *out_fname ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mri_reduce.c,v 1.7 2011/03/02 00:04:24 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 1) argc = 1 ; if (argc < 1) ErrorExit(ERROR_BADPARM, "%s: no input name specified", Progname) ; in_fname = argv[1] ; if (argc < 2) ErrorExit(ERROR_BADPARM, "%s: no output name specified", Progname) ; out_fname = argv[2] ; fprintf(stderr, "reading from %s...", in_fname) ; mri_src = MRIread(in_fname) ; i = 0 ; do { if (i) mri_src = MRIcopy(mri_dst, NULL) ; fprintf(stderr, "\nreducing by 2"); mri_dst = MRIallocSequence(mri_src->width/2, mri_src->height/2, mri_src->depth/2, MRI_FLOAT, mri_src->nframes); MRIreduce(mri_src, mri_dst) ; MRIfree(&mri_src) ; } while (++i < reductions) ; fprintf(stderr, "\nwriting to %s", out_fname) ; MRIwrite(mri_dst, out_fname) ; fprintf(stderr, "\n") ; exit(0) ; return(0) ; }
int main(int argc, char *argv[]) { char **av ; int ac, nargs ; MRI *mri_src, *mri_ref, *mri_tmp ; double accuracy ; MRI_REGION box ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mri_label_accuracy.c,v 1.2 2011/03/02 00:04:22 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; 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) ; mri_src = MRIread(argv[1]) ; if (mri_src == NULL) ErrorExit(ERROR_BADPARM, "%s: could not read input volume %s\n", Progname,argv[1]); MRIboundingBox(mri_src, 0, &box) ; mri_tmp = MRIextractRegionAndPad(mri_src, NULL, &box, PAD) ; MRIfree(&mri_src) ; mri_src = mri_tmp ; if (mri_src->type == MRI_SHORT) { mri_tmp = MRIchangeType(mri_src, MRI_FLOAT, 0, 0, 0) ; MRIfree(&mri_src) ; mri_src = mri_tmp ; } mri_ref = MRIread(argv[2]) ; if (mri_ref == NULL) ErrorExit(ERROR_BADPARM, "%s: could not read reference volume %s\n", Progname,argv[1]); MRIboundingBox(mri_ref, 0, &box) ; mri_tmp = MRIextractRegionAndPad(mri_ref, NULL, &box, PAD) ; MRIfree(&mri_ref) ; mri_ref = mri_tmp ; accuracy = MRIcomputeLabelAccuracy(mri_src, mri_ref, MRI_MEAN_MIN_DISTANCE, stdout) ; if (Gdiag_fp) fclose(Gdiag_fp) ; exit(0) ; return(0) ; }
int main(int argc, char *argv[]) { char **av ; int ac, nargs, nsize ; MRI_SURFACE *mris ; MRI *mri ; nargs = handle_version_option (argc, argv, "$Id: mris_nudge.c,v 1.2 2011/03/02 00:04:31 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Gx = Gy = Gz = -1 ; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 7) usage_exit(1) ; mris = MRISread(argv[1]) ; if (mris == NULL) ErrorExit(ERROR_NOFILE, "%s: could not read surface from %s", Progname, argv[1]) ; MRIScomputeMetricProperties(mris) ; MRISstoreMetricProperties(mris) ; mri = MRIread(argv[2]) ; if (mri == NULL) ErrorExit(ERROR_NOFILE, "%s: could not read volume from %s", Progname, argv[2]) ; target_vnos[nvertices] = atoi(argv[3]) ; target_vals[nvertices] = atof(argv[4]) ; nsize = atoi(argv[5]) ; printf("nudging %d vertex region around vertex %d to target val %2.1f\n", nsize, target_vnos[nvertices], target_vals[nvertices]) ; nvertices++ ; MRISerodeRipped(mris, nsize) ; MRISrepositionSurface(mris, mri, target_vnos, target_vals, nvertices, nsize, sigma) ; MRISunrip(mris) ; printf("writing repositioned surface to %s\n", argv[6]) ; MRISwrite(mris, argv[6]) ; return(0) ; }
//------------------------------------------------------------------------------ int main( int argc, char* argv[] ) { if (argc < 3) { printf("Too few arguments!\nUsage: orbittarget <robot_name> <neighbour_name> [config_file]\n"); return 1; } // init general stuff ErrorInit ( 1, false ); initRandomNumberGenerator(); printf("-----------------------------------\n"); printf("Chatterbox Orbit Target\n"); printf(" build %s %s \n", __DATE__, __TIME__); printf(" compiled against RAPI version %s (%s) build %s\n", RAPI_VERSION(), RAPI_GIT_VERSION(), RAPI_BUILD() ); printf("\n"); printf("Lifting the robot up disables motors\n"); if (signal(SIGINT, quitSig) == SIG_ERR) { PRT_ERR1("Error resetting signal handler %s", strerror(errno)); } // Create robot and its controller robot = new Rapi::CCBRobot (); if ( robot->init() == 0) { Rapi::rapiError->print(); delete robot; exit(-1); } robot->setName(argv[1]); if (argc > 3) robotCtrl = new COrbitTarget ( robot, std::string(argv[3]) ); else robotCtrl = new COrbitTarget ( robot ); robotCtrl->setNNName(std::string(argv[2])); // Blocking call robot->run(); // Clean up robot controller if (robotCtrl) { delete robotCtrl; robotCtrl = NULL; } // Clean up robot if (robot) delete (robot); return 1; }
void SocketUdp::Bind(const EndPoint& ep) { SOCKADDR_IN sin; if (!ep.getIp()) WSAHtonl(this->socket_, INADDR_ANY, &sin.sin_addr.s_addr); else sin.sin_addr.s_addr = inet_addr(ep.getIpStr().c_str()); sin.sin_family = AF_INET; WSAHtons(this->socket_, ep.getPort(), &sin.sin_port); if ((bind(this->socket_, reinterpret_cast<SOCKADDR*>(&sin), sizeof sin)) == SOCKET_ERROR) throw ErrorInit("Cannot bind the socket"); }
PARSEDLLSPEC int ErrorHashCreate(struct _Error *m, int many) { struct _Error **fpnew; int it, ip; int key; if(_ErrorFirst) { ErrorInit(); } for(it=0; it<many; it++) { // // compute hash key // key=ErrorHashKey(m[it].code); // // see if we need to create more room // if(EH[key].many>=EH[key].max) { fpnew=(struct _Error **)malloc((EH[key].max+EENTRY)*sizeof(struct _Error *)); if(fpnew!=0) { if(EH[key].many>0 && EH[key].fptr!=0) { for(ip=0; ip<EH[key].many; ip++) { fpnew[ip]=EH[key].fptr[ip]; } free(EH[key].fptr); } EH[key].fptr=fpnew; EH[key].max+=EENTRY; } else { ErrorHashDestroy(); return -1; } } // // now we should be able to stick the new one in the structure // EH[key].fptr[EH[key].many]= &m[it]; EH[key].many++; } return 0; }
PARSEDLLSPEC void ErrorForward(int art, int code, char *ttype, char *message) { struct _Error *mptr; int response; int type; if(_ErrorFirst) { ErrorInit(); } type=ErrorTypeParse(ttype); mptr=ErrorFind(code); if(mptr==0) { if(type>=0 && type<sizeof(_ErrorResponse)/sizeof(_ErrorResponse[0])) { response=_ErrorResponse[type]; } else { response=0; } } else { type=mptr->type&0xff; response=(mptr->type>>8)&0xff; if(response==0) { if(type>=0 && type<sizeof(_ErrorResponse)/sizeof(_ErrorResponse[0])) { response=_ErrorResponse[type]; } else { response=0; } } } response&=(~(1<<ErrorResponseSpecial)); // // here is where we format the message // if(response!=0) { ErrorPrintIt(art,code,type,response,message); } }
/***-------------------------------------------------------****/ int main(int argc, char *argv[]) { int nargs, index, ac, nvolumes; char **av ; MRI *mri_and = NULL, *mri ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, vcid, "$Name: $"); if (nargs && argc - nargs == 1) exit (0); Progname = argv[0] ; argc -= nargs; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } nvolumes = argc-2 ; if (nvolumes <= 0) usage_exit() ; printf("processing %d input files\n", nvolumes) ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; for (index = 0 ; index < nvolumes ; index++) { char *fname = argv[index+1] ; printf("processing input volume %d of %d: %s\n", index+1, nvolumes, fname) ; mri = MRIread(fname) ; if (index == 0) mri_and = MRIcopy(mri, NULL) ; else MRIand(mri, mri_and, mri_and, 0) ; MRIfree(&mri) ; } printf("writing output to %s\n", argv[argc-1]) ; MRIwrite(mri_and, argv[argc-1]) ; exit(0); } /* end main() */
int main(int argc, char *argv[]) { MRI_SURFACE *mris ; char **av, *in_fname, *out_fname ; int ac, nargs ; MRI *mri_distance ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mris_distance_map.c,v 1.2 2011/03/02 00:04:31 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; 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() ; in_fname = argv[1] ; out_fname = argv[2] ; mris = MRISread(in_fname) ; if (mris == NULL) ErrorExit(ERROR_NOFILE, "%s: could not load surface %s", Progname, out_fname) ; mri_distance = MRIScomputeDistanceMap(mris, NULL, ref_vertex_no) ; MRIwrite(mri_distance, out_fname) ; MRISfree(&mris) ; exit(0) ; return(0) ; /* for ansi */ }
/*---------------------------------------------------------------*/ int main(int argc, char *argv[]) { int nargs; char *surf1_fname ; char *surf2_fname ; char *out_fname ; MRI_SURFACE *mris1, *mris2 ; nargs = handle_version_option (argc, argv, vcid, "$Name: $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; cmdline = argv2cmdline(argc,argv); uname(&uts); getcwd(cwd,2000); Progname = argv[0] ; argc --; argv++; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; if (argc == 0) usage_exit(); parse_commandline(argc, argv); check_options(); if (checkoptsonly) return(0); dump_options(stdout); SUBJECTS_DIR = getenv("SUBJECTS_DIR"); if (SUBJECTS_DIR == NULL) { printf("ERROR: SUBJECTS_DIR not defined in environment\n"); exit(1); } surf1_fname = argv[0] ; surf2_fname = argv[1] ; out_fname = argv[2] ; mris1 = MRISread(surf1_fname) ; if (mris1 == NULL) ErrorExit(ERROR_NOFILE, "could not read surface 1 from %s", surf1_fname) ; mris2 = MRISread(surf2_fname) ; if (mris2 == NULL) ErrorExit(ERROR_NOFILE, "could not read surface 2 from %s", surf2_fname) ; compute_surface_distance(mris1, mris2, mris1) ; MRISwriteValues(mris1, out_fname) ; return 0; }
int main(int argc, char *argv[]) { char **av, *in_fname, *out_fname ; int ac, nargs ; MRI_SURFACE *mris ; float radius, scale ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mris_rescale.c,v 1.5 2011/03/02 00:04:33 nicks Exp $", "$Name: $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; 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() ; in_fname = argv[1] ; out_fname = argv[2] ; mris = MRISread(in_fname) ; if (!mris) ErrorExit(ERROR_NOFILE, "%s: could not read surface file %s", Progname, in_fname) ; radius = MRISaverageRadius(mris) ; scale = DEFAULT_RADIUS / radius ; MRISscaleBrain(mris, mris, scale) ; MRISwrite(mris, out_fname) ; exit(0) ; return(0) ; /* for ansi */ }
int main(int argc, char *argv[]) { char **av, *out_fname, *in_fname ; int ac, nargs ; MRI_SURFACE *mris ; MRI *mri_interior, *mri_template = NULL, *mri_buffer = NULL; char cmdline[CMD_LINE_LEN] ; make_cmd_version_string (argc, argv, "$Id: mris_fill.c,v 1.6 2011/03/02 00:04:32 nicks Exp $", "$Name: $", cmdline); /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mris_fill.c,v 1.6 2011/03/02 00:04:32 nicks Exp $", "$Name: $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; 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() ; in_fname = argv[1] ; out_fname = argv[2] ; fprintf(stderr, "reading surface from %s...\n", in_fname) ; mris = MRISread(in_fname) ; if (template)
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) ; }
int main(int argc, char *argv[]) { double thresh ; MRI *mri, *mri_abs ; char *out_stem, fname[STRLEN] ; MRI_SEGMENTATION *mriseg ; int s ; LABEL *area ; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; mri = MRIread(argv[1]) ; if (mri == NULL) ErrorExit(ERROR_NOFILE, "%s: could not load MRI from %s\n", Progname, argv[1]) ; if (use_abs) mri_abs = MRIabs(mri, NULL) ; else mri_abs = MRIcopy(mri, NULL) ; thresh = atof(argv[2]) ; out_stem = argv[3] ; mriseg = MRIsegment(mri, thresh, 1e10) ; MRIremoveSmallSegments(mriseg, size_thresh) ; printf("segmenting volume at threshold %2.1f yields %d segments\n", thresh, mriseg->nsegments) ; for (s = 0 ; s < mriseg->nsegments ; s++) { area = MRIsegmentToLabel(mriseg, mri_abs, s) ; sprintf(fname, "%s.%3.3d.label", out_stem, s) ; LabelWrite(area, fname) ; } return(0) ; }
/*---------------------------------------------------------------*/ int main(int argc, char *argv[]) { int nargs, n, err; char tmpstr[2000], *signstr=NULL,*SUBJECTS_DIR, fname[2000]; //char *OutDir = NULL; RFS *rfs; int nSmoothsPrev, nSmoothsDelta; MRI *z, *zabs=NULL, *sig=NULL, *p=NULL; int FreeMask = 0; int nthSign, nthFWHM, nthThresh; double sigmax, zmax, threshadj, csize, csizeavg, searchspace,avgvtxarea; int csizen; int nClusters, cmax,rmax,smax; SURFCLUSTERSUM *SurfClustList; struct timeb mytimer; LABEL *clabel; FILE *fp, *fpLog=NULL; nargs = handle_version_option (argc, argv, vcid, "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; cmdline = argv2cmdline(argc,argv); uname(&uts); getcwd(cwd,2000); Progname = argv[0] ; argc --; argv++; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; if (argc == 0) usage_exit(); parse_commandline(argc, argv); check_options(); if (checkoptsonly) return(0); dump_options(stdout); if(LogFile){ fpLog = fopen(LogFile,"w"); if(fpLog == NULL){ printf("ERROR: opening %s\n",LogFile); exit(1); } dump_options(fpLog); } if(SynthSeed < 0) SynthSeed = PDFtodSeed(); srand48(SynthSeed); SUBJECTS_DIR = getenv("SUBJECTS_DIR"); // Create output directory printf("Creating %s\n",OutTop); err = fio_mkdirp(OutTop,0777); if(err) exit(1); for(nthFWHM=0; nthFWHM < nFWHMList; nthFWHM++){ for(nthThresh = 0; nthThresh < nThreshList; nthThresh++){ for(nthSign = 0; nthSign < nSignList; nthSign++){ if(SignList[nthSign] == 0) signstr = "abs"; if(SignList[nthSign] == +1) signstr = "pos"; if(SignList[nthSign] == -1) signstr = "neg"; sprintf(tmpstr,"%s/fwhm%02d/%s/th%02d", OutTop,(int)round(FWHMList[nthFWHM]), signstr,(int)round(10*ThreshList[nthThresh])); sprintf(fname,"%s/%s.csd",tmpstr,csdbase); if(fio_FileExistsReadable(fname)){ printf("ERROR: output file %s exists\n",fname); if(fpLog) fprintf(fpLog,"ERROR: output file %s exists\n",fname); exit(1); } err = fio_mkdirp(tmpstr,0777); if(err) exit(1); } } } // Load the target surface sprintf(tmpstr,"%s/%s/surf/%s.%s",SUBJECTS_DIR,subject,hemi,surfname); printf("Loading %s\n",tmpstr); surf = MRISread(tmpstr); if(!surf) return(1); // Handle masking if(LabelFile){ printf("Loading label file %s\n",LabelFile); sprintf(tmpstr,"%s/%s/label/%s.%s.label", SUBJECTS_DIR,subject,hemi,LabelFile); if(!fio_FileExistsReadable(tmpstr)){ printf(" Cannot find label file %s\n",tmpstr); sprintf(tmpstr,"%s",LabelFile); printf(" Trying label file %s\n",tmpstr); if(!fio_FileExistsReadable(tmpstr)){ printf(" ERROR: cannot read or find label file %s\n",LabelFile); exit(1); } } printf("Loading %s\n",tmpstr); clabel = LabelRead(NULL, tmpstr); mask = MRISlabel2Mask(surf, clabel, NULL); FreeMask = 1; } if(MaskFile){ printf("Loading %s\n",MaskFile); mask = MRIread(MaskFile); if(mask == NULL) exit(1); } if(mask && SaveMask){ sprintf(tmpstr,"%s/mask.mgh",OutTop); printf("Saving mask to %s\n",tmpstr); err = MRIwrite(mask,tmpstr); if(err) exit(1); } // Compute search space searchspace = 0; nmask = 0; for(n=0; n < surf->nvertices; n++){ if(mask && MRIgetVoxVal(mask,n,0,0,0) < 0.5) continue; searchspace += surf->vertices[n].area; nmask++; } printf("Found %d voxels in mask\n",nmask); if(surf->group_avg_surface_area > 0) searchspace *= (surf->group_avg_surface_area/surf->total_area); printf("search space %g mm2\n",searchspace); avgvtxarea = searchspace/nmask; printf("average vertex area %g mm2\n",avgvtxarea); // Determine how many iterations are needed for each FWHM nSmoothsList = (int *) calloc(sizeof(int),nFWHMList); for(nthFWHM=0; nthFWHM < nFWHMList; nthFWHM++){ nSmoothsList[nthFWHM] = MRISfwhm2niters(FWHMList[nthFWHM], surf); printf("%2d %5.1f %4d\n",nthFWHM,FWHMList[nthFWHM],nSmoothsList[nthFWHM]); if(fpLog) fprintf(fpLog,"%2d %5.1f %4d\n",nthFWHM,FWHMList[nthFWHM],nSmoothsList[nthFWHM]); } printf("\n"); // Allocate the CSDs for(nthFWHM=0; nthFWHM < nFWHMList; nthFWHM++){ for(nthThresh = 0; nthThresh < nThreshList; nthThresh++){ for(nthSign = 0; nthSign < nSignList; nthSign++){ csd = CSDalloc(); sprintf(csd->simtype,"%s","null-z"); sprintf(csd->anattype,"%s","surface"); sprintf(csd->subject,"%s",subject); sprintf(csd->hemi,"%s",hemi); sprintf(csd->contrast,"%s","NA"); csd->seed = SynthSeed; csd->nreps = nRepetitions; csd->thresh = ThreshList[nthThresh]; csd->threshsign = SignList[nthSign]; csd->nullfwhm = FWHMList[nthFWHM]; csd->varfwhm = -1; csd->searchspace = searchspace; CSDallocData(csd); csdList[nthFWHM][nthThresh][nthSign] = csd; } } } // Alloc the z map z = MRIallocSequence(surf->nvertices, 1,1, MRI_FLOAT, 1); // Set up the random field specification rfs = RFspecInit(SynthSeed,NULL); rfs->name = strcpyalloc("gaussian"); rfs->params[0] = 0; rfs->params[1] = 1; printf("Thresholds (%d): ",nThreshList); for(n=0; n < nThreshList; n++) printf("%5.2f ",ThreshList[n]); printf("\n"); printf("Signs (%d): ",nSignList); for(n=0; n < nSignList; n++) printf("%2d ",SignList[n]); printf("\n"); printf("FWHM (%d): ",nFWHMList); for(n=0; n < nFWHMList; n++) printf("%5.2f ",FWHMList[n]); printf("\n"); // Start the simulation loop printf("\n\nStarting Simulation over %d Repetitions\n",nRepetitions); if(fpLog) fprintf(fpLog,"\n\nStarting Simulation over %d Repetitions\n",nRepetitions); TimerStart(&mytimer) ; for(nthRep = 0; nthRep < nRepetitions; nthRep++){ msecTime = TimerStop(&mytimer) ; printf("%5d %7.1f ",nthRep,(msecTime/1000.0)/60); if(fpLog) { fprintf(fpLog,"%5d %7.1f ",nthRep,(msecTime/1000.0)/60); fflush(fpLog); } // Synthesize an unsmoothed z map RFsynth(z,rfs,mask); nSmoothsPrev = 0; // Loop through FWHMs for(nthFWHM=0; nthFWHM < nFWHMList; nthFWHM++){ printf("%d ",nthFWHM); if(fpLog) { fprintf(fpLog,"%d ",nthFWHM); fflush(fpLog); } nSmoothsDelta = nSmoothsList[nthFWHM] - nSmoothsPrev; nSmoothsPrev = nSmoothsList[nthFWHM]; // Incrementally smooth z MRISsmoothMRI(surf, z, nSmoothsDelta, mask, z); // smooth z // Rescale RFrescale(z,rfs,mask,z); // Slightly tortured way to get the right p-values because // RFstat2P() computes one-sided, but I handle sidedness // during thresholding. // First, use zabs to get a two-sided pval bet 0 and 0.5 zabs = MRIabs(z,zabs); p = RFstat2P(zabs,rfs,mask,0,p); // Next, mult pvals by 2 to get two-sided bet 0 and 1 MRIscalarMul(p,p,2.0); sig = MRIlog10(p,NULL,sig,1); // sig = -log10(p) for(nthThresh = 0; nthThresh < nThreshList; nthThresh++){ for(nthSign = 0; nthSign < nSignList; nthSign++){ csd = csdList[nthFWHM][nthThresh][nthSign]; // If test is not ABS then apply the sign if(csd->threshsign != 0) MRIsetSign(sig,z,0); // Get the max stats sigmax = MRIframeMax(sig,0,mask,csd->threshsign, &cmax,&rmax,&smax); zmax = MRIgetVoxVal(z,cmax,rmax,smax,0); if(csd->threshsign == 0){ zmax = fabs(zmax); sigmax = fabs(sigmax); } // Mask if(mask) MRImask(sig,mask,sig,0.0,0.0); // Surface clustering MRIScopyMRI(surf, sig, 0, "val"); if(csd->threshsign == 0) threshadj = csd->thresh; else threshadj = csd->thresh - log10(2.0); // one-sided test SurfClustList = sclustMapSurfClusters(surf,threshadj,-1,csd->threshsign, 0,&nClusters,NULL); // Actual area of cluster with max area csize = sclustMaxClusterArea(SurfClustList, nClusters); // Number of vertices of cluster with max number of vertices. // Note: this may be a different cluster from above! csizen = sclustMaxClusterCount(SurfClustList, nClusters); // Area of this cluster based on average vertex area. This just scales // the number of vertices. csizeavg = csizen * avgvtxarea; if(UseAvgVtxArea) csize = csizeavg; // Store results csd->nClusters[nthRep] = nClusters; csd->MaxClusterSize[nthRep] = csize; csd->MaxSig[nthRep] = sigmax; csd->MaxStat[nthRep] = zmax; } // Sign } // Thresh } // FWHM printf("\n"); if(fpLog) fprintf(fpLog,"\n"); if(SaveEachIter || fio_FileExistsReadable(SaveFile)) SaveOutput(); if(fio_FileExistsReadable(StopFile)) { printf("Found stop file %s\n",StopFile); goto finish; } } // Simulation Repetition finish: SaveOutput(); msecTime = TimerStop(&mytimer) ; printf("Total Sim Time %g min (%g per rep)\n", msecTime/(1000*60.0),(msecTime/(1000*60.0))/nthRep); if(fpLog) fprintf(fpLog,"Total Sim Time %g min (%g per rep)\n", msecTime/(1000*60.0),(msecTime/(1000*60.0))/nthRep); if(DoneFile){ fp = fopen(DoneFile,"w"); fprintf(fp,"%g\n",msecTime/(1000*60.0)); fclose(fp); } printf("mri_mcsim done\n"); if(fpLog){ fprintf(fpLog,"mri_mcsim done\n"); fclose(fpLog); } exit(0); }
/*--------------------------------------------------*/ int main(int argc, char **argv) { int nargs, err, asegid, c, r, s, nctx, annot,vtxno,nripped; int annotid, IsCortex=0, IsWM=0, IsHypo=0, hemi=0, segval=0; int RibbonVal=0,nbrute=0; float dmin=0.0, lhRibbonVal=0, rhRibbonVal=0; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, vcid, "$Name: stable5 $"); if (nargs && argc - nargs == 1) { exit (0); } argc -= nargs; Progname = argv[0] ; argc --; argv++; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; if (argc == 0) { usage_exit(); } SUBJECTS_DIR = getenv("SUBJECTS_DIR"); if (SUBJECTS_DIR==NULL) { printf("ERROR: SUBJECTS_DIR not defined in environment\n"); exit(1); } parse_commandline(argc, argv); check_options(); dump_options(stdout); /* ------ Load subject's lh white surface ------ */ sprintf(tmpstr,"%s/%s/surf/lh.white",SUBJECTS_DIR,subject); printf("\nReading lh white surface \n %s\n",tmpstr); lhwhite = MRISread(tmpstr); if (lhwhite == NULL) { fprintf(stderr,"ERROR: could not read %s\n",tmpstr); exit(1); } /* ------ Load subject's lh pial surface ------ */ sprintf(tmpstr,"%s/%s/surf/lh.pial",SUBJECTS_DIR,subject); printf("\nReading lh pial surface \n %s\n",tmpstr); lhpial = MRISread(tmpstr); if (lhpial == NULL) { fprintf(stderr,"ERROR: could not read %s\n",tmpstr); exit(1); } if (lhwhite->nvertices != lhpial->nvertices) { printf("ERROR: lh white and pial have a different number of " "vertices (%d,%d)\n", lhwhite->nvertices,lhpial->nvertices); exit(1); } /* ------ Load lh annotation ------ */ sprintf(annotfile,"%s/%s/label/lh.%s.annot",SUBJECTS_DIR,subject,annotname); printf("\nLoading lh annotations from %s\n",annotfile); err = MRISreadAnnotation(lhwhite, annotfile); if (err) { printf("ERROR: MRISreadAnnotation() failed %s\n",annotfile); exit(1); } /* ------ Load subject's rh white surface ------ */ sprintf(tmpstr,"%s/%s/surf/rh.white",SUBJECTS_DIR,subject); printf("\nReading rh white surface \n %s\n",tmpstr); rhwhite = MRISread(tmpstr); if (rhwhite == NULL) { fprintf(stderr,"ERROR: could not read %s\n",tmpstr); exit(1); } /* ------ Load subject's rh pial surface ------ */ sprintf(tmpstr,"%s/%s/surf/rh.pial",SUBJECTS_DIR,subject); printf("\nReading rh pial surface \n %s\n",tmpstr); rhpial = MRISread(tmpstr); if (rhpial == NULL) { fprintf(stderr,"ERROR: could not read %s\n",tmpstr); exit(1); } if (rhwhite->nvertices != rhpial->nvertices) { printf("ERROR: rh white and pial have a different " "number of vertices (%d,%d)\n", rhwhite->nvertices,rhpial->nvertices); exit(1); } /* ------ Load rh annotation ------ */ sprintf(annotfile,"%s/%s/label/rh.%s.annot",SUBJECTS_DIR,subject,annotname); printf("\nLoading rh annotations from %s\n",annotfile); err = MRISreadAnnotation(rhwhite, annotfile); if (err) { printf("ERROR: MRISreadAnnotation() failed %s\n",annotfile); exit(1); } if (lhwhite->ct) { printf("Have color table for lh white annotation\n"); } if (rhwhite->ct) { printf("Have color table for rh white annotation\n"); } //print_annotation_table(stdout); if (UseRibbon) { sprintf(tmpstr,"%s/%s/mri/lh.ribbon.mgz",SUBJECTS_DIR,subject); printf("Loading lh ribbon mask from %s\n",tmpstr); lhRibbon = MRIread(tmpstr); if (lhRibbon == NULL) { printf("ERROR: loading %s\n",tmpstr); exit(1); } sprintf(tmpstr,"%s/%s/mri/rh.ribbon.mgz",SUBJECTS_DIR,subject); printf("Loading rh ribbon mask from %s\n",tmpstr); rhRibbon = MRIread(tmpstr); if (rhRibbon == NULL) { printf("ERROR: loading %s\n",tmpstr); exit(1); } } if (UseNewRibbon) { sprintf(tmpstr,"%s/%s/mri/ribbon.mgz",SUBJECTS_DIR,subject); printf("Loading ribbon segmentation from %s\n",tmpstr); RibbonSeg = MRIread(tmpstr); if (RibbonSeg == NULL) { printf("ERROR: loading %s\n",tmpstr); exit(1); } } if (LabelHypoAsWM) { sprintf(tmpstr,"%s/%s/mri/filled.mgz",SUBJECTS_DIR,subject); printf("Loading filled from %s\n",tmpstr); filled = MRIread(tmpstr); if (filled == NULL) { printf("ERROR: loading filled %s\n",tmpstr); exit(1); } } // ------------ Rip ----------------------- if (RipUnknown) { printf("Ripping vertices labeled as unkown\n"); nripped = 0; for (vtxno = 0; vtxno < lhwhite->nvertices; vtxno++) { annot = lhwhite->vertices[vtxno].annotation; CTABfindAnnotation(lhwhite->ct, annot, &annotid); // Sometimes the annotation will be "none" indicated by // annotid = -1. We interpret this as "unknown". if (annotid == 0 || annotid == -1) { lhwhite->vertices[vtxno].ripflag = 1; lhpial->vertices[vtxno].ripflag = 1; nripped++; } } printf("Ripped %d vertices from left hemi\n",nripped); nripped = 0; for (vtxno = 0; vtxno < rhwhite->nvertices; vtxno++) { annot = rhwhite->vertices[vtxno].annotation; CTABfindAnnotation(rhwhite->ct, annot, &annotid); if (annotid == 0 || annotid == -1) { rhwhite->vertices[vtxno].ripflag = 1; rhpial->vertices[vtxno].ripflag = 1; nripped++; } } printf("Ripped %d vertices from right hemi\n",nripped); } printf("\n"); printf("Building hash of lh white\n"); lhwhite_hash = MHTfillVertexTableRes(lhwhite, NULL,CURRENT_VERTICES,hashres); printf("\n"); printf("Building hash of lh pial\n"); lhpial_hash = MHTfillVertexTableRes(lhpial, NULL,CURRENT_VERTICES,hashres); printf("\n"); printf("Building hash of rh white\n"); rhwhite_hash = MHTfillVertexTableRes(rhwhite, NULL,CURRENT_VERTICES,hashres); printf("\n"); printf("Building hash of rh pial\n"); rhpial_hash = MHTfillVertexTableRes(rhpial, NULL,CURRENT_VERTICES,hashres); /* ------ Load ASeg ------ */ sprintf(tmpstr,"%s/%s/mri/aseg.mgz",SUBJECTS_DIR,subject); if (!fio_FileExistsReadable(tmpstr)) { sprintf(tmpstr,"%s/%s/mri/aseg.mgh",SUBJECTS_DIR,subject); if (!fio_FileExistsReadable(tmpstr)) { sprintf(tmpstr,"%s/%s/mri/aseg/COR-.info",SUBJECTS_DIR,subject); if (!fio_FileExistsReadable(tmpstr)) { printf("ERROR: cannot find aseg\n"); exit(1); } else { sprintf(tmpstr,"%s/%s/mri/aseg/",SUBJECTS_DIR,subject); } } } printf("\nLoading aseg from %s\n",tmpstr); ASeg = MRIread(tmpstr); if (ASeg == NULL) { printf("ERROR: loading aseg %s\n",tmpstr); exit(1); } mritmp = MRIchangeType(ASeg,MRI_INT,0,0,1); MRIfree(&ASeg); ASeg = mritmp; if (CtxSegFile) { printf("Loading Ctx Seg File %s\n",CtxSegFile); CtxSeg = MRIread(CtxSegFile); if (CtxSeg == NULL) { exit(1); } } AParc = MRIclone(ASeg,NULL); if (OutDistFile != NULL) { Dist = MRIclone(ASeg,NULL); mritmp = MRIchangeType(Dist,MRI_FLOAT,0,0,0); if (mritmp == NULL) { printf("ERROR: could change type\n"); exit(1); } MRIfree(&Dist); Dist = mritmp; } Vox2RAS = MRIxfmCRS2XYZtkreg(ASeg); printf("ASeg Vox2RAS: -----------\n"); MatrixPrint(stdout,Vox2RAS); printf("-------------------------\n"); CRS = MatrixAlloc(4,1,MATRIX_REAL); CRS->rptr[4][1] = 1; RAS = MatrixAlloc(4,1,MATRIX_REAL); RAS->rptr[4][1] = 1; if (crsTest) { printf("Testing point %d %d %d\n",ctest,rtest,stest); err = FindClosestLRWPVertexNo(ctest,rtest,stest, &lhwvtx, &lhpvtx, &rhwvtx, &rhpvtx, Vox2RAS, lhwhite, lhpial, rhwhite, rhpial, lhwhite_hash, lhpial_hash, rhwhite_hash, rhpial_hash); printf("Result: err = %d\n",err); exit(err); } printf("\nLabeling Slice\n"); nctx = 0; annot = 0; annotid = 0; nbrute = 0; // Go through each voxel in the aseg for (c=0; c < ASeg->width; c++) { printf("%3d ",c); if (c%20 ==19) { printf("\n"); } fflush(stdout); for (r=0; r < ASeg->height; r++) { for (s=0; s < ASeg->depth; s++) { asegid = MRIgetVoxVal(ASeg,c,r,s,0); if (asegid == 3 || asegid == 42) { IsCortex = 1; } else { IsCortex = 0; } if (asegid >= 77 && asegid <= 82) { IsHypo = 1; } else { IsHypo = 0; } if (asegid == 2 || asegid == 41) { IsWM = 1; } else { IsWM = 0; } if (IsHypo && LabelHypoAsWM && MRIgetVoxVal(filled,c,r,s,0)) { IsWM = 1; } // integrate surface information // // Only Do This for GM,WM or Unknown labels in the ASEG !!! // // priority is given to the ribbon computed from the surface // namely // ribbon=GM => GM // aseg=GM AND ribbon=WM => WM // ribbon=UNKNOWN => UNKNOWN if (UseNewRibbon && ( IsCortex || IsWM || asegid==0 ) ) { RibbonVal = MRIgetVoxVal(RibbonSeg,c,r,s,0); MRIsetVoxVal(ASeg,c,r,s,0, RibbonVal); if (RibbonVal==2 || RibbonVal==41) { IsWM = 1; IsCortex = 0; } else if (RibbonVal==3 || RibbonVal==42) { IsWM = 0; IsCortex = 1; } if (RibbonVal==0) { IsWM = 0; IsCortex = 0; } } // If it's not labeled as cortex or wm in the aseg, skip if (!IsCortex && !IsWM) { continue; } // If it's wm but not labeling wm, skip if (IsWM && !LabelWM) { continue; } // Check whether this point is in the ribbon if (UseRibbon) { lhRibbonVal = MRIgetVoxVal(lhRibbon,c,r,s,0); rhRibbonVal = MRIgetVoxVal(rhRibbon,c,r,s,0); if (IsCortex) { // ASeg says it's in cortex if (lhRibbonVal < 0.5 && rhRibbonVal < 0.5) { // but it is not part of the ribbon, // so set it to unknown (0) and go to the next voxel. MRIsetVoxVal(ASeg,c,r,s,0,0); continue; } } } // Convert the CRS to RAS CRS->rptr[1][1] = c; CRS->rptr[2][1] = r; CRS->rptr[3][1] = s; RAS = MatrixMultiply(Vox2RAS,CRS,RAS); vtx.x = RAS->rptr[1][1]; vtx.y = RAS->rptr[2][1]; vtx.z = RAS->rptr[3][1]; // Get the index of the closest vertex in the // lh.white, lh.pial, rh.white, rh.pial if (UseHash) { lhwvtx = MHTfindClosestVertexNo(lhwhite_hash,lhwhite,&vtx,&dlhw); lhpvtx = MHTfindClosestVertexNo(lhpial_hash, lhpial, &vtx,&dlhp); rhwvtx = MHTfindClosestVertexNo(rhwhite_hash,rhwhite,&vtx,&drhw); rhpvtx = MHTfindClosestVertexNo(rhpial_hash, rhpial, &vtx,&drhp); if (lhwvtx < 0 && lhpvtx < 0 && rhwvtx < 0 && rhpvtx < 0) { /* printf(" Could not map to any surface with hash table:\n"); printf(" crs = %d %d %d, ras = %6.4f %6.4f %6.4f \n", c,r,s,vtx.x,vtx.y,vtx.z); printf(" Using brute force search %d ... \n",nbrute); fflush(stdout); */ lhwvtx = MRISfindClosestVertex(lhwhite,vtx.x,vtx.y,vtx.z,&dlhw); lhpvtx = MRISfindClosestVertex(lhpial,vtx.x,vtx.y,vtx.z,&dlhp); rhwvtx = MRISfindClosestVertex(rhwhite,vtx.x,vtx.y,vtx.z,&drhw); rhpvtx = MRISfindClosestVertex(rhpial,vtx.x,vtx.y,vtx.z,&drhp); nbrute ++; //exit(1); } } else { lhwvtx = MRISfindClosestVertex(lhwhite,vtx.x,vtx.y,vtx.z,&dlhw); lhpvtx = MRISfindClosestVertex(lhpial,vtx.x,vtx.y,vtx.z,&dlhp); rhwvtx = MRISfindClosestVertex(rhwhite,vtx.x,vtx.y,vtx.z,&drhw); rhpvtx = MRISfindClosestVertex(rhpial,vtx.x,vtx.y,vtx.z,&drhp); } if (lhwvtx < 0) { dlhw = 1000000000000000.0; } if (lhpvtx < 0) { dlhp = 1000000000000000.0; } if (rhwvtx < 0) { drhw = 1000000000000000.0; } if (rhpvtx < 0) { drhp = 1000000000000000.0; } if (dlhw <= dlhp && dlhw < drhw && dlhw < drhp && lhwvtx >= 0) { annot = lhwhite->vertices[lhwvtx].annotation; hemi = 1; if (lhwhite->ct) { CTABfindAnnotation(lhwhite->ct, annot, &annotid); } else { annotid = annotation_to_index(annot); } dmin = dlhw; } if (dlhp < dlhw && dlhp < drhw && dlhp < drhp && lhpvtx >= 0) { annot = lhwhite->vertices[lhpvtx].annotation; hemi = 1; if (lhwhite->ct) { CTABfindAnnotation(lhwhite->ct, annot, &annotid); } else { annotid = annotation_to_index(annot); } dmin = dlhp; } if (drhw < dlhp && drhw < dlhw && drhw <= drhp && rhwvtx >= 0) { annot = rhwhite->vertices[rhwvtx].annotation; hemi = 2; if (rhwhite->ct) { CTABfindAnnotation(rhwhite->ct, annot, &annotid); } else { annotid = annotation_to_index(annot); } dmin = drhw; } if (drhp < dlhp && drhp < drhw && drhp < dlhw && rhpvtx >= 0) { annot = rhwhite->vertices[rhpvtx].annotation; hemi = 2; if (rhwhite->ct) { CTABfindAnnotation(rhwhite->ct, annot, &annotid); } else { annotid = annotation_to_index(annot); } dmin = drhp; } // Sometimes the annotation will be "none" indicated by // annotid = -1. We interpret this as "unknown". if (annotid == -1) { annotid = 0; } // why was this here in the first place? /* if (annotid == 0 && lhwvtx >= 0 && lhpvtx >= 0 && rhwvtx >= 0 && rhpvtx >= 0) { printf("%d %d %d %d\n", lhwhite->vertices[lhwvtx].ripflag, lhpial->vertices[lhpvtx].ripflag, rhwhite->vertices[rhwvtx].ripflag, rhpial->vertices[rhpvtx].ripflag); } */ if ( IsCortex && hemi == 1) { segval = annotid+1000 + baseoffset; //ctx-lh } if ( IsCortex && hemi == 2) { segval = annotid+2000 + baseoffset; //ctx-rh } if (!IsCortex && hemi == 1) { segval = annotid+3000 + baseoffset; // wm-lh } if (!IsCortex && hemi == 2) { segval = annotid+4000 + baseoffset; // wm-rh } if (!IsCortex && dmin > dmaxctx && hemi == 1) { segval = 5001; } if (!IsCortex && dmin > dmaxctx && hemi == 2) { segval = 5002; } // This is a hack for getting the right cortical seg with --rip-unknown // The aparc+aseg should be passed as CtxSeg. if (IsCortex && CtxSeg) { segval = MRIgetVoxVal(CtxSeg,c,r,s,0); } MRIsetVoxVal(ASeg,c,r,s,0,segval); MRIsetVoxVal(AParc,c,r,s,0,annot); if (OutDistFile != NULL) { MRIsetVoxVal(Dist,c,r,s,0,dmin); } if (debug || annotid == -1) { // Gets here when there is no label at the found vertex. // This is different than having a vertex labeled as "unknown" if (!debug) { continue; } printf("\n"); printf("Found closest vertex, but it has no label.\n"); printf("aseg id = %d\n",asegid); printf("crs = %d %d %d, ras = %6.4f %6.4f %6.4f \n", c,r,s,vtx.x,vtx.y,vtx.z); if (lhwvtx > 0) printf("lhw %d %7.5f %6.4f %6.4f %6.4f\n", lhwvtx, dlhw, lhwhite->vertices[lhwvtx].x, lhwhite->vertices[lhwvtx].y, lhwhite->vertices[lhwvtx].z); if (lhpvtx > 0) printf("lhp %d %7.5f %6.4f %6.4f %6.4f\n", lhpvtx, dlhp, lhpial->vertices[lhpvtx].x, lhpial->vertices[lhpvtx].y, lhpial->vertices[lhpvtx].z); if (rhwvtx > 0) printf("rhw %d %7.5f %6.4f %6.4f %6.4f\n", rhwvtx, drhw, rhwhite->vertices[rhwvtx].x, rhwhite->vertices[rhwvtx].y, rhwhite->vertices[rhwvtx].z); if (rhpvtx > 0) printf("rhp %d %7.5f %6.4f %6.4f %6.4f\n", rhpvtx, drhp, rhpial->vertices[rhpvtx].x, rhpial->vertices[rhpvtx].y, rhpial->vertices[rhpvtx].z); printf("annot = %d, annotid = %d\n",annot,annotid); CTABprintASCII(lhwhite->ct,stdout); continue; } nctx++; } } } printf("nctx = %d\n",nctx); printf("Used brute-force search on %d voxels\n",nbrute); if (FixParaHipWM) { /* This is a bit of a hack. There are some vertices that have been ripped because they are "unkown". When the above alorithm finds these, it searches for the closest known vertex. If this is less than dmax away, then the wm voxel gets labeled accordingly. However, there are often some voxels near ventralDC that are just close enough in 3d space to parahip to get labeled even though they are very far away along the surface. These voxels end up forming an island. CCSegment() will eliminate any islands. Unforunately, CCSegment() uses 6-neighbor (face) definition of connectedness, so some voxels may be eliminated. */ printf("Fixing Parahip LH WM\n"); CCSegment(ASeg, 3016, 5001); //3016 = lhphwm, 5001 = unsegmented WM left printf("Fixing Parahip RH WM\n"); CCSegment(ASeg, 4016, 5002); //4016 = rhphwm, 5002 = unsegmented WM right } printf("Writing output aseg to %s\n",OutASegFile); MRIwrite(ASeg,OutASegFile); if (OutAParcFile != NULL) { printf("Writing output aparc to %s\n",OutAParcFile); MRIwrite(AParc,OutAParcFile); } if (OutDistFile != NULL) { printf("Writing output dist file to %s\n",OutDistFile); MRIwrite(Dist,OutDistFile); } return(0); }
int main(int argc, char *argv[]) { int done = FALSE; opterr = 0; //fprintf(stderr, "ctrack started."); c_control = C_RUN; srand((int)time(NULL)); ErrorInit(); ConfigInit(); // initializes verbose; must be called before any output ReadConfig(TRUE); // default loc. TorrentDBCreate(); unsigned int p; while (!done) { switch (getopt(argc, argv, "+vqVhrdt:u:p:c:")) { // + means "don't shuffle args" case '?': // invalid option PrintSyntax(1); case 'h': // help option PrintSyntax(0); case 'V': printf("ctrack " VERSION "\n"); return 0; break; case 'v': SetConfigBool(CFG_VERBOSE, TRUE); log("Verbose mode"); break; case 'q': SetConfigBool(CFG_VERBOSE, FALSE); log("Quiet mode"); break; case 't': if (b_assign(atoi(optarg),1,65535,(int *)&p)) SetConfigUInt(CFG_HTTP_PORT, p); break; case 'u': if (b_assign(atoi(optarg),1,65535,(int *)&p)) SetConfigUInt(CFG_UDP_PORT, p); break; case 'p': if (b_assign(atoi(optarg),1,65535,(int *)&p)) SetConfigUInt(CFG_SERVER_PORT, p); break; case 'd': SetConfigBool(CFG_DAEMON, TRUE); break; case 'c': //config file SetConfigString(CFG_CONFIG_FILE, optarg); ReadConfig(FALSE); break; case -1: //end of options done = TRUE; break; default: PrintSyntax(1); break; }//switch }//while int i; for (i = optind; i < argc; i++) { PTorrentInfo t; char ibuffer[20]; if (strtohash(argv[i], ibuffer)) { NewTorrentInfo(&t, ibuffer); } else { errorm("Invalid hash: %s", argv[i]); } }//for //TODO:parse args //TODO:init torrent db #ifdef DAEMON_SUPPORT if (GetConfigBool(CFG_DAEMON) == TRUE) { /* Our process ID and Session ID */ pid_t pid, sid; /* Fork off the parent process */ pid = fork(); if (pid < 0) { exit(EXIT_FAILURE); } /* If we got a good PID, then we can exit the parent process. */ if (pid > 0) { exit(EXIT_SUCCESS); } /* Change the file mode mask */ umask(0); /* Create a new SID for the child process */ sid = setsid(); if (sid < 0) { errorm("setsid() failed: %s", str_error()); exit(EXIT_FAILURE); } /* Change the current working directory */ if ((chdir("/")) < 0) { errorm("chdir() failed: %s", str_error()); exit(EXIT_FAILURE); } /* Close out the standard file descriptors */ close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); if (daemon(TRUE, FALSE) != 0) errorf(E_SYSTEM, "daemon() failed: %S", str_error()); } else { extern int asdaemon; asdaemon = TRUE; } #endif //SetupSignalHandlers sigset_t set; int sig; while (c_control == C_RUN) { sigfillset(&set); pthread_sigmask(SIG_SETMASK, &set, NULL); if (GetConfigBool(CFG_HTTP_SERVER)) { // HTTP server if (SetUpListener()) HTTPThreadInit(); } if (GetConfigBool(CFG_UDP_SERVER)) { // UDP server UDPThreadInit(); } //TODO: sigwait while (c_control == C_RUN) { sigwait(&set, &sig); logf("Caught signal #%d", sig); switch (sig) { case SIGINT: c_control = C_TERMINATE; log("Exitting..."); break; case SIGHUP: c_control = C_RESTART; log("Restarting..."); ReadConfig(FALSE); break; case SIGSEGV: c_control = C_TERMINATE; log("Exitting..."); }//switch }//while ThreadsDestroy(); CloseTCPSocket(); CloseUDPSocket(); if (c_control == C_RESTART) { c_control = C_RUN; } }//while log("exit "); return ((sig==SIGINT) ? EXIT_SUCCESS : EXIT_FAILURE); }
int main(int argc, char *argv[]) { char *in_fname, *out_fname, **av, *xform_fname, fname[STRLEN] ; MRI *mri_in, *mri_tmp ; int ac, nargs, msec, minutes, seconds; int input, ninputs ; struct timeb start ; TRANSFORM *transform = NULL ; char cmdline[CMD_LINE_LEN], line[STRLEN], *cp, subject[STRLEN], sdir[STRLEN], base_name[STRLEN] ; FILE *fp ; make_cmd_version_string (argc, argv, "$Id: mri_fuse_intensity_images.c,v 1.2 2011/06/02 14:05:10 fischl Exp $", "$Name: $", cmdline); /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mri_fuse_intensity_images.c,v 1.2 2011/06/02 14:05:10 fischl Exp $", "$Name: $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; setRandomSeed(-1L) ; Progname = argv[0] ; DiagInit(NULL, NULL, NULL) ; ErrorInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 5) ErrorExit (ERROR_BADPARM, "usage: %s [<options>] <longitudinal time point file> <in vol> <transform file> <out vol> \n", Progname) ; in_fname = argv[2] ; xform_fname = argv[3] ; out_fname = argv[4] ; transform = TransformRead(xform_fname) ; if (transform == NULL) ErrorExit(ERROR_NOFILE, "%s: could not read transform from %s", Progname, xform_fname) ; TimerStart(&start) ; FileNamePath(argv[1], sdir) ; cp = strrchr(sdir, '/') ; if (cp) { strcpy(base_name, cp+1) ; *cp = 0 ; // remove last component of path, which is base subject name } ninputs = 0 ; fp = fopen(argv[1], "r") ; if (fp == NULL) ErrorExit(ERROR_NOFILE, "%s: could not read time point file %s", Progname, argv[1]) ; do { cp = fgetl(line, STRLEN-1, fp) ; if (cp != NULL && strlen(cp) > 0) { subjects[ninputs] = (char *)calloc(strlen(cp)+1, sizeof(char)) ; strcpy(subjects[ninputs], cp) ; ninputs++ ; } } while (cp != NULL && strlen(cp) > 0) ; fclose(fp) ; printf("processing %d timepoints in SUBJECTS_DIR %s...\n", ninputs, sdir) ; for (input = 0 ; input < ninputs ; input++) { sprintf(subject, "%s.long.%s", subjects[input], base_name) ; printf("reading subject %s - %d of %d\n", subject, input+1, ninputs) ; sprintf(fname, "%s/%s/mri/%s", sdir, subject, in_fname) ; mri_tmp = MRIread(fname) ; if (!mri_tmp) ErrorExit(ERROR_NOFILE, "%s: could not read input MR volume from %s", Progname, fname) ; MRImakePositive(mri_tmp, mri_tmp) ; if (input == 0) { mri_in = MRIallocSequence(mri_tmp->width, mri_tmp->height, mri_tmp->depth, mri_tmp->type, ninputs) ; if (!mri_in) ErrorExit(ERROR_NOMEMORY, "%s: could not allocate input volume %dx%dx%dx%d", mri_tmp->width,mri_tmp->height,mri_tmp->depth,ninputs) ; MRIcopyHeader(mri_tmp, mri_in) ; } if (mask_fname) { int i ; MRI *mri_mask ; mri_mask = MRIread(mask_fname) ; if (!mri_mask) ErrorExit(ERROR_NOFILE, "%s: could not open mask volume %s.\n", Progname, mask_fname) ; for (i = 1 ; i < WM_MIN_VAL ; i++) MRIreplaceValues(mri_mask, mri_mask, i, 0) ; MRImask(mri_tmp, mri_mask, mri_tmp, 0, 0) ; MRIfree(&mri_mask) ; } MRIcopyFrame(mri_tmp, mri_in, 0, input) ; MRIfree(&mri_tmp) ; } MRIaddCommandLine(mri_in, cmdline) ; // try to bring the images closer to each other at each voxel where they seem to come from the same distribution { MRI *mri_frame1, *mri_frame2 ; double rms_after ; mri_frame1 = MRIcopyFrame(mri_in, NULL, 0, 0) ; mri_frame2 = MRIcopyFrame(mri_in, NULL, 1, 0) ; rms_after = MRIrmsDiff(mri_frame1, mri_frame2) ; printf("RMS before intensity cohering = %2.2f\n", rms_after) ; MRIfree(&mri_frame1) ; MRIfree(&mri_frame2) ; if (0) normalize_timepoints(mri_in, 2.0, cross_time_sigma) ; else normalize_timepoints_with_parzen_window(mri_in, cross_time_sigma) ; mri_frame1 = MRIcopyFrame(mri_in, NULL, 0, 0) ; mri_frame2 = MRIcopyFrame(mri_in, NULL, 1, 0) ; rms_after = MRIrmsDiff(mri_frame1, mri_frame2) ; MRIfree(&mri_frame1) ; MRIfree(&mri_frame2) ; printf("RMS after intensity cohering = %2.2f (sigma=%2.2f)\n", rms_after, cross_time_sigma) ; } for (input = 0 ; input < ninputs ; input++) { sprintf(fname, "%s/%s.long.%s/mri/%s", sdir, subjects[input], base_name, out_fname) ; printf("writing normalized volume to %s...\n", fname) ; if (MRIwriteFrame(mri_in, fname, input) != NO_ERROR) ErrorExit(ERROR_BADFILE, "%s: could not write normalized volume to %s",Progname, fname); } MRIfree(&mri_in) ; printf("done.\n") ; msec = TimerStop(&start) ; seconds = nint((float)msec/1000.0f) ; minutes = seconds / 60 ; seconds = seconds % 60 ; printf("normalization took %d minutes and %d seconds.\n", minutes, seconds) ; if (diag_fp) fclose(diag_fp) ; exit(0) ; return(0) ; }
int main(int argc, char *argv[]) { char **av, *hemi, *subject_name, *cp, fname[STRLEN]; char *parc_name, *annot_name ; int ac, nargs, vno, i ; MRI_SURFACE *mris ; MRI *mri_parc ; VERTEX *v ; double d ; Real x, y, z, xw, yw, zw ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mris_sample_parc.c,v 1.31 2016/12/11 14:33:38 fischl Exp $", "$Name: $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 4) usage_exit() ; subject_name = argv[1] ; hemi = argv[2] ; parc_name = argv[3] ; annot_name = argv[4] ; if (strlen(sdir) == 0) /* if not specified explicitly as option */ { cp = getenv("SUBJECTS_DIR") ; if (!cp) ErrorExit(ERROR_BADPARM, "%s: SUBJECTS_DIR not defined in environment.\n", Progname) ; strcpy(sdir, cp) ; } if (parc_name[0] == '/') // full path specified strcpy(fname, parc_name) ; else sprintf(fname, "%s/%s/mri/%s", sdir, subject_name, parc_name) ; printf("reading parcellation volume from %s...\n", fname) ; mri_parc = MRIread(fname) ; if (!mri_parc) ErrorExit(ERROR_NOFILE, "%s: could not read input volume %s", Progname, fname) ; if (mask_fname) { MRI *mri_mask, *mri_tmp ; mri_tmp = MRIread(mask_fname) ; if (mri_tmp == NULL) ErrorExit(ERROR_BADPARM, "%s: could not load mask volume %s", Progname, mask_fname) ; mri_mask = MRIclone(mri_tmp, NULL) ; MRIcopyLabel(mri_tmp, mri_mask, mask_val) ; MRIdilate(mri_mask, mri_mask) ; MRIdilate(mri_mask, mri_mask) ; MRIdilate(mri_mask, mri_mask) ; MRIdilate(mri_mask, mri_mask) ; MRIfree(&mri_tmp) ; mri_tmp = MRIclone(mri_parc, NULL) ; MRIcopyLabeledVoxels(mri_parc, mri_mask, mri_tmp, mask_val) ; MRIfree(&mri_parc) ; mri_parc = mri_tmp ; if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON) MRIwrite(mri_parc, "p.mgz") ; MRIfree(&mri_mask) ; } for (i = 0 ; i < ntrans ; i++) { MRIreplaceValues(mri_parc, mri_parc, trans_in[i], trans_out[i]) ; } sprintf(fname, "%s/%s/surf/%s.%s", sdir, subject_name, hemi, surf_name) ; printf("reading input surface %s...\n", fname) ; mris = MRISread(fname) ; if (!mris) ErrorExit(ERROR_NOFILE, "%s: could not read surface file %s", Progname, fname) ; MRISsaveVertexPositions(mris, ORIGINAL_VERTICES) ; MRIScomputeMetricProperties(mris) ; if (avgs > 0) MRISaverageVertexPositions(mris, avgs) ; if (FZERO(proj_mm)) { if (MRISreadCurvatureFile(mris, thickness_name) != NO_ERROR) ErrorExit(ERROR_NOFILE, "%s: could not read thickness file %s", Progname, thickness_name) ; } if (color_table_fname) { mris->ct = CTABreadASCII(color_table_fname) ; if (mris->ct == NULL) ErrorExit(ERROR_NOFILE, "%s: could not read color file %s", Progname, color_table_fname) ; } if (sample_from_vol_to_surf) // sample from volume to surface */ { MRIsampleParcellationToSurface(mris, mri_parc) ; } else /* sample from surface to volume */ { for (vno = 0 ; vno < mris->nvertices ; vno++) { v = &mris->vertices[vno] ; if (v->ripflag) continue ; if (vno == Gdiag_no) DiagBreak() ; if (!FZERO(proj_mm)) d = proj_mm ; else d = v->curv*proj_frac ; /* halfway out */ x = v->x+d*v->nx ; y = v->y+d*v->ny ; z = v->z+d*v->nz ; MRIsurfaceRASToVoxel(mri_parc, x, y, z, &xw, &yw, &zw) ; v->annotation = v->val = MRIfindNearestNonzero(mri_parc, wsize, xw, yw, zw, ((float)wsize-1)/2) ; if (v->val == 0xffffffff) DiagBreak() ; } } if (replace_label) replace_vertices_with_label(mris, mri_parc, replace_label, proj_mm); if (unknown_label >= 0) { LABEL **labels, *label ; int nlabels, i, biggest_label, most_vertices, nzero ; #define TMP_LABEL 1000 for (nzero = vno = 0 ; vno < mris->nvertices ; vno++) { v = &mris->vertices[vno] ; if (v->annotation == 0) { v->annotation = TMP_LABEL; nzero++ ; } } printf("%d unknown vertices found\n", nzero) ; MRISsegmentAnnotated(mris, &labels, &nlabels, 10) ; most_vertices = 0 ; biggest_label = -1 ; for (i = 0 ; i < nlabels ; i++) { label = labels[i] ; if (mris->vertices[label->lv[0].vno].annotation == TMP_LABEL) { if (label->n_points > most_vertices) { biggest_label = i ; most_vertices = label->n_points ; } } } if (biggest_label >= 0) { label = labels[biggest_label] ; printf("replacing label # %d with %d vertices " "(vno=%d) with label %d\n", biggest_label, label->n_points, label->lv[0].vno, unknown_label) ; for (i = 0 ; i < label->n_points ; i++) { v = &mris->vertices[label->lv[i].vno] ; v->annotation = v->val = unknown_label ; } } for (nzero = vno = 0 ; vno < mris->nvertices ; vno++) { v = &mris->vertices[vno] ; if (v->annotation == TMP_LABEL) { v->annotation = 0; nzero++ ; } } printf("after replacement, %d unknown vertices found\n", nzero) ; MRISmodeFilterZeroVals(mris) ; /* get rid of the rest of the unknowns by mode filtering */ for (i = 0 ; i < nlabels ; i++) LabelFree(&labels[i]) ; free(labels) ; } MRIScopyValsToAnnotations(mris) ; if (fix_topology != 0) fix_label_topology(mris, fix_topology) ; if (mode_filter) { printf("mode filtering sample labels...\n") ; #if 0 MRISmodeFilterZeroVals(mris) ; #else MRISmodeFilterVals(mris, mode_filter) ; #endif for (vno = 0 ; vno < mris->nvertices ; vno++) { v = &mris->vertices[vno] ; if (v->ripflag) continue ; v->annotation = v->val ; } } /* this will fill in the v->annotation field from the v->val ones */ translate_indices_to_annotations(mris, translation_fname) ; if (label_index >= 0) { int index ; LABEL *area ; printf("writing label to %s...\n", annot_name) ; MRISclearMarks(mris) ; for (vno = 0 ; vno < mris->nvertices ; vno++) { if (vno == Gdiag_no) DiagBreak() ; v = &mris->vertices[vno] ; if (v->annotation > 0) DiagBreak() ; CTABfindAnnotation(mris->ct, v->annotation, &index); if (index == label_index) v->marked = 1 ; } area = LabelFromMarkedSurface(mris) ; if (nclose > 0) { LabelDilate(area, mris, nclose, CURRENT_VERTICES) ; LabelErode(area, mris, nclose) ; } LabelWrite(area, annot_name) ; } else { printf("writing annotation to %s...\n", annot_name) ; MRISwriteAnnotation(mris, annot_name) ; } /* MRISreadAnnotation(mris, fname) ;*/ exit(0) ; return(0) ; /* for ansi */ }
int main(int argc, char *argv[]) { char **av, *in_fname, *out_fname ; int ac, nargs, i, label ; MRI *mri_in, *mri_out, *mri_kernel, *mri_smoothed ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mri_extract_label.c,v 1.13 2011/03/02 00:04:15 nicks Exp $", "$Name: $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 4) usage_exit() ; in_fname = argv[1] ; out_fname = argv[argc-1] ; printf("reading volume from %s...\n", in_fname) ; mri_in = MRIread(in_fname) ; if (!mri_in) ErrorExit(ERROR_NOFILE, "%s: could not read MRI volume %s", Progname, in_fname) ; if (out_like_fname) { MRI *mri_tmp = MRIread(out_like_fname) ; if (!mri_tmp) ErrorExit (ERROR_NOFILE, "%s: could not read template volume from %s", out_like_fname) ; mri_out = MRIalloc(mri_tmp->width, mri_tmp->height, mri_tmp->depth, mri_tmp->type) ; /* MRIcopyHeader(mri_tmp, mri_out) ;*/ MRIfree(&mri_tmp) ; } else mri_out = MRIclone(mri_in, NULL) ; for (i = 2 ; i < argc-1 ; i++) { label = atoi(argv[i]) ; printf("extracting label %d (%s)\n", label, cma_label_to_name(label)) ; extract_labeled_image(mri_in, transform, label, mri_out) ; } if (!FZERO(sigma)) { printf("smoothing extracted volume...\n") ; mri_kernel = MRIgaussian1d(sigma, 10*sigma) ; mri_smoothed = MRIconvolveGaussian(mri_out, NULL, mri_kernel) ; MRIfree(&mri_out) ; mri_out = mri_smoothed ; } /* removed for gcc3.3 * vsprintf(out_fname, out_fname, (va_list) &label) ; */ if (dilate > 0) { int i ; printf("dilating output volume %d times...\n", dilate) ; for (i = 0 ; i < dilate ; i++) MRIdilate(mri_out, mri_out) ; } if (erode > 0) { int i ; printf("eroding output volume %d times...\n", erode) ; for (i = 0 ; i < erode ; i++) MRIerode(mri_out, mri_out) ; } printf("writing output to %s.\n", out_fname) ; MRIwrite(mri_out, out_fname) ; if (exit_none_found && (nvoxels == 0)) { printf("No voxels with specified label were found!\n"); exit(1); } exit(0) ; return(0) ; /* for ansi */ }
initpyodbc(void) #endif { ErrorInit(); if (PyType_Ready(&ConnectionType) < 0 || PyType_Ready(&CursorType) < 0 || PyType_Ready(&RowType) < 0 || PyType_Ready(&CnxnInfoType) < 0) return MODRETURN(0); Object module; #if PY_MAJOR_VERSION >= 3 module.Attach(PyModule_Create(&moduledef)); #else module.Attach(Py_InitModule4("pyodbc", pyodbc_methods, module_doc, NULL, PYTHON_API_VERSION)); #endif pModule = module.Get(); if (!module || !import_types() || !CreateExceptions()) return MODRETURN(0); init_locale_info(); const char* szVersion = TOSTRING(PYODBC_VERSION); PyModule_AddStringConstant(module, "version", (char*)szVersion); PyModule_AddIntConstant(module, "threadsafety", 1); PyModule_AddStringConstant(module, "apilevel", "2.0"); PyModule_AddStringConstant(module, "paramstyle", "qmark"); PyModule_AddObject(module, "pooling", Py_True); Py_INCREF(Py_True); PyModule_AddObject(module, "lowercase", Py_False); Py_INCREF(Py_False); PyModule_AddObject(module, "native_uuid", Py_False); Py_INCREF(Py_False); PyModule_AddObject(module, "Connection", (PyObject*)&ConnectionType); Py_INCREF((PyObject*)&ConnectionType); PyModule_AddObject(module, "Cursor", (PyObject*)&CursorType); Py_INCREF((PyObject*)&CursorType); PyModule_AddObject(module, "Row", (PyObject*)&RowType); Py_INCREF((PyObject*)&RowType); // Add the SQL_XXX defines from ODBC. for (unsigned int i = 0; i < _countof(aConstants); i++) PyModule_AddIntConstant(module, (char*)aConstants[i].szName, aConstants[i].value); PyModule_AddObject(module, "Date", (PyObject*)PyDateTimeAPI->DateType); Py_INCREF((PyObject*)PyDateTimeAPI->DateType); PyModule_AddObject(module, "Time", (PyObject*)PyDateTimeAPI->TimeType); Py_INCREF((PyObject*)PyDateTimeAPI->TimeType); PyModule_AddObject(module, "Timestamp", (PyObject*)PyDateTimeAPI->DateTimeType); Py_INCREF((PyObject*)PyDateTimeAPI->DateTimeType); PyModule_AddObject(module, "DATETIME", (PyObject*)PyDateTimeAPI->DateTimeType); Py_INCREF((PyObject*)PyDateTimeAPI->DateTimeType); PyModule_AddObject(module, "STRING", (PyObject*)&PyString_Type); Py_INCREF((PyObject*)&PyString_Type); PyModule_AddObject(module, "NUMBER", (PyObject*)&PyFloat_Type); Py_INCREF((PyObject*)&PyFloat_Type); PyModule_AddObject(module, "ROWID", (PyObject*)&PyInt_Type); Py_INCREF((PyObject*)&PyInt_Type); PyObject* binary_type; #if PY_VERSION_HEX >= 0x02060000 binary_type = (PyObject*)&PyByteArray_Type; #else binary_type = (PyObject*)&PyBuffer_Type; #endif PyModule_AddObject(module, "BINARY", binary_type); Py_INCREF(binary_type); PyModule_AddObject(module, "Binary", binary_type); Py_INCREF(binary_type); I(null_binary != 0); // must be initialized first PyModule_AddObject(module, "BinaryNull", null_binary); PyModule_AddIntConstant(module, "UNICODE_SIZE", sizeof(Py_UNICODE)); PyModule_AddIntConstant(module, "SQLWCHAR_SIZE", sizeof(SQLWCHAR)); if (!PyErr_Occurred()) { module.Detach(); } else { ErrorCleanup(); } return MODRETURN(pModule); }
PARSEDLLSPEC int ErrorPrint(int code, ...) { va_list ap; char buffer[MBUFFER]; struct _Error *mptr; int type; int response; char *format; char uformat[MBUFFER]; if(_ErrorFirst) { ErrorInit(); } mptr=ErrorFind(code); if(mptr==0) { type=ErrorWarning; response=(1<<ErrorResponseShowCode)|(1<<ErrorResponseShowType)|(1<<ErrorResponseShowMessage); SformatOutput(uformat,MBUFFER-1,"Unknown error."); uformat[MBUFFER-1]=0; format=uformat; } else { type=mptr->type&0xff; response=(mptr->type>>8)&0xff; if(response==0) { if(type>=0 && type<sizeof(_ErrorResponse)/sizeof(_ErrorResponse[0])) { response=_ErrorResponse[type]; } else { response=0; } } format=mptr->format; } response&=(~(1<<ErrorResponseSpecial)); // // here is where we format the message // if(response!=0) { if(response&(1<<ErrorResponseShowMessage)) { va_start(ap, code); #if defined(LINUX) || defined(__APPLE__) vsnprintf(buffer,MBUFFER-1,format,ap); #else _vsnprintf(buffer,MBUFFER-1,format,ap); #endif va_end(ap); buffer[MBUFFER-1]=0; } else { buffer[0]=0; } ErrorPrintIt(-1,code,type,response,buffer); } return code; }
/***-------------------------------------------------------****/ int main(int argc, char *argv[]) { int nargs, ac, nvolumes; char **av ; MRI *outmri0 = NULL, *outmri1 = NULL, *outmri2 = NULL, *outmri3 = NULL, *outmri4 = NULL, *segmri ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, vcid, "$Name: $"); if (nargs && argc - nargs == 1) exit (0); Progname = argv[0] ; argc -= nargs; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } nvolumes = argc-1 ; printf("processing %d input files\n", nvolumes) ; if (nvolumes != 2) usage_exit() ; printf("processing %d input files\n", nvolumes) ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; char *fname = argv[1] ; printf("processing segmentation input volume %s\n", fname) ; segmri = MRIread(fname) ; //int width = segmri->width ; //int height = segmri->height ; //int depth = segmri->depth ; char *outputfname = argv[2] ; printf("output fname %s\n", outputfname) ; // GM/WM outmri0 = MRIcopy(segmri, NULL) ; // MRIwrite(outmri0, "/tmp/segmri.mgz") ; correct_gmwm_boundaries(segmri, outmri0); // MRIwrite(outmri0, "/tmp/outmri0.mgz") ; // putamen / pallidum outmri1 = MRIcopy(outmri0, NULL) ; correct_putamen_pallidum_boundaries(outmri0, outmri1); // MRIwrite(outmri1, "/tmp/outmri1.mgz") ; // GM / WM outmri2 = MRIcopy(outmri1, NULL) ; correct_gmwm_boundaries_2(outmri1, outmri2); // MRIwrite(outmri2, "/tmp/outmri2.mgz") ; // find largest connected components and close holes outmri3 = MRIcopy(segmri, NULL) ; MRIvalueFill(outmri3, 0); correct_largestCC_and_fill_holes(outmri2, outmri3); // MRIwrite(outmri3, "/tmp/outmri3.mgz") ; // fill leftover voxels in origiinal mask outmri4 = MRIcopy(outmri3, NULL) ; fill_leftover_voxels(segmri, outmri3, outmri4); // MRIwrite(outmri4, "/tmp/outmri4.mgz") ; // outmri0 = MRIcopy(outmri4, NULL) ; correct_gmwm_boundaries(outmri4, outmri0); // MRIwrite(outmri0, "/tmp/redone-outmri0.mgz") ; outmri1 = MRIcopy(outmri0, NULL) ; correct_putamen_pallidum_boundaries(outmri0, outmri1); // MRIwrite(outmri1, "/tmp/redone-outmri1.mgz") ; outmri2 = MRIcopy(outmri1, NULL) ; correct_gmwm_boundaries_2(outmri1, outmri2); // MRIwrite(outmri2, "/tmp/redone-outmri2.mgz") ; // printf("writing output to %s\n", outputfname) ; MRIwrite(outmri2, outputfname) ; MRIfree(&segmri) ; MRIfree(&outmri0); MRIfree(&outmri1); MRIfree(&outmri2); MRIfree(&outmri3); MRIfree(&outmri4); exit(0); } /* end main() */
/*---------------------------------------------------------------*/ int main(int argc, char **argv) { int n, v, c; FILE *fp; char *covarname; char SumFile[2000]; char DatFile[2000]; char MatFile[2000]; char OutGDFile[2000]; int nargs; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mri_gdfglm.c,v 1.8.2.1 2011/05/05 15:29:51 greve Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; argc --; argv++; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; if (argc == 0) usage_exit(); printf("\n\n"); printf("%s ",Progname); for (n=0; n < argc; n++) printf("%s ",argv[n]); printf("\n\n"); printf("%s\n\n",vcid); parse_commandline(argc, argv); check_options(); dump_options(stdout); X = gdfMatrixDODS(fsgd,NULL); if (X==NULL) exit(1); if (debug) MatrixPrint(stdout,X); Xnorm = MatrixNormalizeCol(X,NULL,NULL); Xcondition = sqrt(MatrixNSConditionNumber(Xnorm)); MatrixFree(&Xnorm); printf("INFO: Normalized Design Matrix Condition Number is %g\n", Xcondition); if (Xcondition > 100000) { printf("ERROR: Design matrix is badly conditioned, check for linear\n" "dependency between columns (ie, two or more columns \n" "that add up to another column).\n\n"); exit(1); } printf("Extracting DepVar\n"); y = DVTgetDepVar(dvt,nDepVarList,DepVarList,wDepVar); printf("Performing Estimation\n"); pinvX = MatrixPseudoInverse(X,NULL); beta = MatrixMultiply(pinvX,y,NULL); yhat = MatrixMultiply(X,beta,NULL); r = MatrixSubtract(y,yhat,NULL); dof = X->rows-X->cols; rvar = VectorVar(r, &rmean); rvar = rvar * (X->rows-1)/dof; printf("Beta: -----------------\n"); MatrixPrint(stdout,beta); printf("---------------------------------\n\n"); printf("rvar = %g, rstd = %g\n",rvar,sqrt(rvar)); C = gdfContrastDODS(fsgd, wClass, wCovar); printf("C: -----------------\n"); MatrixPrint(stdout,C); printf("---------------------------------\n\n"); ces = MatrixMultiply(C,beta,NULL); vmf = ContrastVMF(X,C); tval = ces->rptr[1][1]/sqrt(rvar*vmf); sigtval = sigt(tval, rint(dof)); printf("ces = %g, vmf = %g, t = %g, sigt = %g\n", ces->rptr[1][1],vmf,tval,sigtval); sprintf(SumFile,"%s.sum",OutBase); fp = fopen(SumFile,"w"); fprintf(fp,"mri_gdfglm summary file\n\n"); fprintf(fp,"Group Descriptor File %s\n",GDFile); fprintf(fp,"Dependent Variable File %s\n",DVTFile); fprintf(fp,"Dependent Variable Weights: "); if (wDepVar == NULL) fprintf(fp," all 1s\n"); else { fprintf(fp,"\n"); for (n=0; n < nwDepVar; n++) fprintf(fp," %s %g\n",DepVarList[n],wDepVar[n]); } fprintf(fp,"\n"); fprintf(fp,"Class Contrast Weights: "); if (nwClass == 0) fprintf(fp," all 1s\n"); else { fprintf(fp,"\n"); for (n=0; n < nwClass; n++) fprintf(fp," %s %g\n",fsgd->classlabel[n],wClass[n]); } fprintf(fp,"\n"); fprintf(fp,"Covar Contrast Weights: "); if (nwCovar == 0) if (!TestOffset) fprintf(fp," all 1s\n"); else fprintf(fp," all 0s\n"); else { fprintf(fp,"\n"); for (n=0; n < nwCovar; n++) fprintf(fp," %s %g",CovarList[n],wCovar[n]); fprintf(fp,"\n"); } fprintf(fp,"TestOffset = %d\n",TestOffset); fprintf(fp,"\n"); fprintf(fp,"Parameter Estimates and Contrast Weighting:\n\n"); n = 0; for (v=0; v < fsgd->nvariables+1; v++) { if (v==0) covarname = "Offset"; else covarname = fsgd->varlabel[v-1]; for (c=0; c < fsgd->nclasses; c++) { fprintf(fp,"%-10s %-10s %12.5f %5.2f\n",fsgd->classlabel[c], covarname,beta->rptr[n+1][1],C->rptr[1][n+1]); n++; } fprintf(fp,"\n"); } fprintf(fp,"\n"); fprintf(fp,"Residual Variance %g\n",rvar); fprintf(fp,"Residual StdDev %g\n",sqrt(rvar)); fprintf(fp,"DOF %g\n",dof); fprintf(fp,"\n"); fprintf(fp,"Contrast Effect Size %g\n",ces->rptr[1][1]); fprintf(fp,"Variance Reduction Factor %g\n",1/vmf); fprintf(fp,"t-Ratio %g\n",tval); fprintf(fp,"Significance %g\n",sigtval); fprintf(fp,"\n"); fclose(fp); /*----------------------------------------*/ sprintf(DatFile,"%s.dat",OutBase); fp = fopen(DatFile,"w"); for (n=0; n < fsgd->ninputs; n++) { fprintf(fp,"%2d ",n); if (KeepSubjId) fprintf(fp,"%s",fsgd->subjid[n]); for (v=0; v < fsgd->nvariables; v++) fprintf(fp," %g",fsgd->varvals[n][v]); fprintf(fp," %g %g",y->rptr[n+1][1],yhat->rptr[n+1][1]); fprintf(fp,"\n"); } fclose(fp); /*----------------------------------------*/ sprintf(MatFile,"%s.mat",OutBase); all = MatrixHorCat(X,y,NULL); all = MatrixHorCat(all,yhat,NULL); all = MatrixHorCat(all,r,NULL); MatlabWrite(all,MatFile,"X"); /*----------------------------------------*/ sprintf(OutGDFile,"%s.gdf",OutBase); fp = fopen(OutGDFile,"w"); gdfPrintHeader(fp,fsgd); fclose(fp); /*----------------------------------------*/ WriteAllClassDat(OutBase,fsgd,y,yhat,X,beta); return(0); }