Exemple #1
0
void VParseFilterCmd (int noptions, VOptionDescRec opts[],
		      int argc, char **argv, FILE **inp, FILE **outp)
{
  static VStringConst in_file, out_file;
  static VBoolean in_found, out_found;
  static VOptionDescRec io_opts[] = {
    { "in", VStringRepn, 1, & in_file, & in_found, NULL, "Input file" },
    { "out", VStringRepn, 1, & out_file, & out_found, NULL, "Output file" }
  };
  int i, n;
  VOptionDescRec options[100];
    
  /* Check that number of options will not overflow the options array. */
  if (noptions >= 98) {
    VWarning("VParseFilterCmd: Too many options allowed");
    noptions = 98;
  }

  /* Copy options into a new list and add the "in" and "out" options. */
  n = 0;
  if (inp)
    options[n++] = io_opts[0];
  if (outp)
    options[n++] = io_opts[1];
  for (i = 0; i < noptions; i++, n++)
    options[n] = opts[i];
    
  /* Parse command line arguments and identify the input and output files: */
  if (! VParseCommand (n, options, & argc, argv) ||
      (inp && ! VIdentifyFiles (n, options, "in", & argc, argv, 0)) ||
      (outp && ! VIdentifyFiles (n, options, "out", & argc, argv, 1)))
    goto Usage;

  /* Any remaining unparsed arguments are erroneous: */
  if (argc > 1) {
    VReportBadArgs (argc, argv);
  Usage:  VReportUsage (argv[0], n, options,
			inp ? (outp ? "[infile] [outfile]" : "[infile]") :
			(outp ? "[outfile]" : NULL));
    exit (EXIT_FAILURE);
  }

  /* Open the input and output files: */
  if (inp)
    *inp = VOpenInputFile (in_file, TRUE);
  if (outp)
    *outp = VOpenOutputFile (out_file, TRUE);
}
Exemple #2
0
int
main(int argc, char *argv[]) {
    static VArgVector in_files;
    static VString out_filename;
    static VBoolean in_found, out_found;
    static VOptionDescRec  options[] = {
        {"in", VStringRepn, 0, & in_files, & in_found, NULL, "Input files" },
        {"out", VStringRepn, 1, & out_filename, & out_found, NULL, "Output file" }
    };
    FILE *fp = NULL;
    VStringConst in_filename;
    VAttrList list = NULL, out_list = NULL;
    VImage *design = NULL, tmp = NULL, dest = NULL;
    VAttrListPosn posn;
    int  i, nimages;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vcatdesign V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* Parse command line arguments: */
    if(! VParseCommand(VNumber(options), options, & argc, argv) ||
            ! VIdentifyFiles(VNumber(options), options, "in", & argc, argv, 0) ||
            ! VIdentifyFiles(VNumber(options), options, "out", & argc, argv, -1))
        goto Usage;
    if(argc > 1) {
        VReportBadArgs(argc, argv);
Usage:
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    /* Read each input file */
    nimages = in_files.number;
    design = (VImage *) VMalloc(sizeof(VImage) * nimages);
    for(i = 0; i < nimages; i++) {
        in_filename = ((VStringConst *) in_files.vector)[i];
        fprintf(stderr, " reading:  %s\n", in_filename);
        fp = VOpenInputFile(in_filename, TRUE);
        list = VReadFile(fp, NULL);
        if(! list)
            VError("Error reading file %s", in_filename);
        fclose(fp);
        for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & tmp);
            if(VPixelRepn(tmp) == VFloatRepn || VPixelRepn(tmp) == VDoubleRepn) {
                design[i] = tmp;
                break;
            }
        }
    }
    /* process */
    dest = ConcatDesigns(design, nimages);
    out_list = VCreateAttrList();
    VAppendAttr(out_list, "image", NULL, VImageRepn, dest);
    /* Output: */
    VHistory(VNumber(options), options, prg_name, &list, &out_list);
    fp = VOpenOutputFile(out_filename, TRUE);
    if(!fp)
        VError(" error opening outout file %s", out_filename);
    if(! VWriteFile(fp, out_list))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    return 0;
}
Exemple #3
0
/* the main routine */
int main (int argc,char *argv[]) {
  QApplication::setColorSpec( QApplication::ManyColor );                                                                                  

  /* initialize preferences variables */
  pr = prefsini();

  /* write out the revision string */
  char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vlview V%s", ver);
  
  fprintf (stderr, "%s\n", prg_name);
    
  /* Parse command line arguments and identify files: */
  if (! VParseCommand (VNumber (options), options, & argc, argv) ||
      ! VIdentifyFiles (VNumber (options), options, "in", & argc, argv, 0))
    goto Usage;
  if (argc > 1) {
    VReportBadArgs (argc, argv);
  Usage:	VReportUsage (argv[0], VNumber (options), options, NULL);
    exit (EXIT_FAILURE);
  }

  /* A. Hagert: exceptions */
  if (mincol == 123456 && maxcol == 123456) { pr->col_min = 0; pr->col_max = 0; }
  else if (mincol != 123456 && maxcol == 123456) 
    { printf("ERROR: maximum not given -> ignoring given minimum.\n"); pr->col_min = 0; pr->col_max = 0; }
  else if (mincol == 123456 && maxcol != 123456)
    { printf("ERROR: minimum not given -> ignoring given maximum.\n"); pr->col_min = 0; pr->col_max = 0; }
  else if (mincol<=maxcol) { pr->col_min=mincol; pr->col_max=maxcol; }
  else { printf("ERROR: given minimum is higher than maximum -> ignoring both.\n"); 
  pr->col_min = 0; pr->col_max = 0; 
  }
  
  /* set verbose option to prefs */
  pr->prg_name=prg_name;
  pr->verbose=verbose;
  pr->raw=rawfile;
  pr->des=desfile;
  pr->beta=betafile;
  pr->colortable=colortable_filename;
  pr->graph[0]=graphfile;
  pr->files=0;
  pr->infilenum=in_files.number;
  pr->zmapfilenum=zmap_files.number;
  pr->thresh=th11;
  pr->background0=background[0];
  pr->background1=background[1];

  if (pr->infilenum > pr->zmapfilenum)
    pr->files=pr->infilenum;
  else 
    pr->files=pr->zmapfilenum;

  if (pr->infilenum==0) 
    VError("No infile specified");

  if (pr->files>1) 
    VError("Use 'vlv' for visualization of data sets > 1");

  /* get the number of graphs (pr->g_number) */
  myload_.testFiles();

  /* initialize open the main window */
  QApplication a( argc, argv );
  lView ww;
  
  a.setMainWidget( &ww );
  ww.show();
  

  return a.exec();
  /* end of the program */
}
Exemple #4
0
int main(int argc, char *argv[]) {
    VAttrList list, out_list;
    VImage src;
    VImage dest = NULL;
    VAttrListPosn posn;
    VString str;
    int nimages;
    char historystr[] = "history";
    char prg_name[100];
    char ver[100];
    getLipsiaVersion(ver, sizeof(ver));
    sprintf(prg_name, "vdelcereb V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* Parse command line arguments: */
    if(!VParseCommand(VNumber(options), options, &argc, argv) ||
            ! VIdentifyFiles(VNumber(options), options, "in", & argc, argv, 0) ||
            ! VIdentifyFiles(VNumber(options), options, "out", & argc, argv, -1))
        goto Usage;
    if(argc > 1) {
        VReportBadArgs(argc, argv);
Usage:
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    /* Read source image(s): */
    if(strcmp(in_filename, "-") == 0)
        in_file = stdin;
    else {
        in_file = fopen(in_filename, "r");
        if(! in_file)
            VError("Failed to open input file %s", in_filename);
    }
    if(!(list = VReadFile(in_file, NULL)))
        exit(EXIT_FAILURE);
    fclose(in_file);
    /* Process image */
    nimages = 0;
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & src);
        dest = VCerebellum(src);
        VSetAttrValue(& posn, NULL, VImageRepn, dest);
        VDestroyImage(src);
        nimages++;
        break;
    }
    /* Create outlist */
    out_list = VCreateAttrList();
    /* Make History */
    VHistory(VNumber(options), options, prg_name, &list, &out_list);
    /*  Alle Attribute (ausser history:) in die neue Liste schreiben: */
    for(VFirstAttr(list, &posn); VAttrExists(&posn); VNextAttr(&posn)) {
        if(strncmp(VGetAttrName(&posn), historystr, strlen(historystr)) == 0)
            continue;
        switch(VGetAttrRepn(&posn)) {
        case VImageRepn:
            VGetAttrValue(&posn, NULL, VImageRepn, &src);
            VAppendAttr(out_list, VGetAttrName(&posn), NULL, VImageRepn, src);
            break;
        case VStringRepn:
            VGetAttrValue(&posn, NULL, VStringRepn, &str);
            VAppendAttr(out_list, VGetAttrName(&posn), NULL, VImageRepn, str);
            break;
        default:
            break;
        }
    }
    /* Write the results to the output file: */
    if(strcmp(out_filename, "-") == 0)
        out_file = stdout;
    else {
        out_file = fopen(out_filename, "w");
        if(! out_file)
            VError("Failed to open output file %s", out_filename);
    }
    if(VWriteFile(out_file, out_list)) {
        if(verbose >= 1)
            fprintf(stderr, "%s: processed %d image%s.\n",
                    argv[0], nimages, nimages == 1 ? "" : "s");
        fprintf(stderr, "%s: done.\n", argv[0]);
    }
    return 0;
}
Exemple #5
0
int main(int argc, char *argv[]) {
    static VArgVector in_files;
    static VString  out_filename;
    static VBoolean level  = FALSE;
    static VBoolean zscore = FALSE;
    static VBoolean in_found, out_found;
    static VOptionDescRec options[] = {
        {
            "in", VStringRepn, 0, & in_files,  & in_found, NULL,
            "Contrast images"
        },
        {
            "out", VStringRepn, 1, & out_filename, & out_found, NULL,
            "Output file"
        },
        {
            "level", VBooleanRepn, 1, & level, VOptionalOpt, NULL,
            "Whether to produce output to be used for 3rd level analysis"
        }
        /*    { "zscore", VBooleanRepn, 1, & zscore, VOptionalOpt, NULL,
          "Whether to produce z-scores as output"} */
    };
    FILE *f;
    VStringConst in_filename;
    VAttrList list, out_list;
    VAttrListPosn posn;
    VImage src = NULL;
    VImage cbeta_images[N], sd_images[N];
    int i, nimages = 0;
    VString str = NULL;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vbayes V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* Parse command line arguments: */
    if(! VParseCommand(VNumber(options), options, & argc, argv) ||
            ! VIdentifyFiles(VNumber(options), options, "in", & argc, argv, 0) ||
            ! VIdentifyFiles(VNumber(options), options, "out", & argc, argv, -1))
        goto Usage;
    if(argc > 1) {
        VReportBadArgs(argc, argv);
Usage:
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    nimages = in_files.number;
    fprintf(stderr, "Processing %d input files\n\n", nimages);
    if(nimages >= N)
        VError("Too many input images, max: %d", N);
    if(nimages == 0)
        VError("Input images missing");
    /* loop through all input files */
    for(i = 0; i < nimages; i++) {
        in_filename = ((VStringConst *) in_files.vector)[i];
        fprintf(stderr, "%s\n", in_filename);
        f = fopen((char *)in_filename, "r");
        if(! f)
            VError("Failed to open input file %s", in_filename);
        if(!(list = VReadFile(f, NULL)))
            exit(EXIT_FAILURE);
        fclose(f);
        for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VPixelRepn(src) != VFloatRepn)
                continue;
            VGetAttr(VImageAttrList(src), "modality", NULL, VStringRepn, &str);
            if(strcmp(str, "conimg") == 0) {
                cbeta_images[i] = VCopyImage(src, NULL, VAllBands);
            } else if(strcmp(str, "std_dev") == 0 || strcmp(str, "sd") == 0) {
                sd_images[i] = VCopyImage(src, NULL, VAllBands);
            } else
                VError(" Illegal input file! Make sure to use con-images as input");
        }
    }
    /* calculate probabilities */
    out_list = VBayes(cbeta_images, sd_images, nimages, level, zscore);
    if(out_list == NULL)
        VError(" no result");
    /*
    ** output
    */
    VHistory(VNumber(options), options, prg_name, &list, &out_list);
    if(strcmp(out_filename, "-") == 0)
        VError("Output file required");
    f = fopen(out_filename, "w");
    if(! f)
        VError("Failed to open output file %s", out_filename);
    if(! VWriteFile(f, out_list))
        exit(EXIT_FAILURE);
    fprintf(stderr, "\n%s: done \n", argv[0]);
    return EXIT_SUCCESS;
}
Exemple #6
0
int main(int argc, char *argv[]) {
    /* command line arguments */
    static VString out_filename;
    static VArgVector in_files;
    static VString trans_filename = "";
    static VBoolean in_found, out_found;
    static VShort minval = 0;
    static VBoolean compress = TRUE;
    static VFloat resolution = 3;
    static VOptionDescRec options[] = {
        { "in", VStringRepn, 0, & in_files, & in_found, NULL, "Input file" },
        { "out", VStringRepn, 1, & out_filename, & out_found, NULL, "Output file" },
        {
            "trans", VStringRepn, 1, &trans_filename, VRequiredOpt, NULL,
            "File containing transformation matrix"
        },
        {
            "resolution", VFloatRepn, 1, &resolution, VOptionalOpt, NULL,
            "Output voxel resolution in mm"
        },
        {
            "minval", VShortRepn, 1, &minval, VOptionalOpt, NULL,
            "Signal threshold"
        },
        {
            "compress", VBooleanRepn, 1, &compress, VOptionalOpt, NULL,
            "Whether to compress empty slices"
        }
    };
    VStringConst in_filename;
    FILE *in_file, *out_file, *fp;
    VAttrList list, list1, out_list;
    VAttrListPosn posn;
    VImage trans = NULL;
    VImage *dst_image;
    VImageInfo *imageInfo;
    int nobject = 0, ntimesteps = 0, nbands = 0, nrows = 0, ncols = 0;
    VString ca, cp, extent, str;
    int found = 0;
    int j, dest_nbands;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vfunctrans V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* Parse command line arguments: */
    if(! VParseCommand(VNumber(options), options, & argc, argv) ||
            ! VIdentifyFiles(VNumber(options), options, "in", & argc, argv, 0) ||
            ! VIdentifyFiles(VNumber(options), options, "out", & argc, argv, -1))
        goto Usage;
    if(argc > 1) {
        VReportBadArgs(argc, argv);
Usage:
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    if(resolution <= 0)
        VError(" 'resolution' must be an integer > 0");
    /*
    ** Read the transformation matrix:
    */
    fp = VOpenInputFile(trans_filename, TRUE);
    list1 = VReadFile(fp, NULL);
    if(! list1)
        VError("Error reading image");
    fclose(fp);
    for(VFirstAttr(list1, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        if(strncmp(VGetAttrName(&posn), "transform", 9) != 0)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & trans);
        break;
    }
    if(trans == NULL)
        VError("transformation matrix not found");
    /*
    ** check attributes
    */
    if(VGetAttr(VImageAttrList(trans), "ca", NULL,
                VStringRepn, (VPointer) & ca) != VAttrFound)
        VError(" attribute 'ca' missing in transformation matrix ");
    if(VGetAttr(VImageAttrList(trans), "cp", NULL,
                VStringRepn, (VPointer) & cp) != VAttrFound)
        VError(" attribute 'cp' missing in transformation matrix ");
    if(VGetAttr(VImageAttrList(trans), "extent", NULL,
                VStringRepn, (VPointer) & extent) != VAttrFound)
        VError(" attribute 'extent' missing in transformation matrix ");
    /*
    ** open in-file
    */
    if(in_files.number < 1 || in_files.number > 1)
        VError(" incorrect number of input files: %d", in_files.number);
    in_filename = ((VStringConst *) in_files.vector)[0];
    if(strcmp(in_filename, "-") == 0)
        in_file = stdin;
    else {
        in_file = fopen((char *)in_filename, "r");
        if(! in_file)
            VError("Failed to open input file %s", in_filename);
    }
    /*
    ** read file info
    */
    if(! ReadHeader(in_file))
        VError("error reading header");
    if(!(list = ReadAttrList(in_file)))
        VError("error reading attr list");
    j = 0;
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        j++;
    }
    imageInfo = (VImageInfo *) VMalloc(sizeof(VImageInfo) * (j + 1));
    nobject = nbands = found = 0;
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        str = VGetAttrName(&posn);
        if(strncmp(str, "history", 7) == 0) {
            nobject++;
            continue;
        }
        VImageInfoIni(&imageInfo[nbands]);
        if(! VGetImageInfo(in_file, list, nobject, &imageInfo[nbands]))
            VError(" error reading image info");
        if(imageInfo[nbands].repn == VShortRepn) {
            found = 1;
            nrows = imageInfo[nbands].nrows;
            ncols = imageInfo[nbands].ncolumns;
            ntimesteps = imageInfo[nbands].nbands;
            nbands++;
        }
        nobject++;
    }
    fclose(in_file);
    if(!found)
        VError(" couldn't find functional data");
    /*
    ** process each time step
    */
    dst_image = VFunctrans(in_filename, imageInfo, nbands, trans, resolution,
                           ntimesteps, minval, compress, &dest_nbands);
    /*
    ** output
    */
    out_list = VCreateAttrList();
    VHistory(VNumber(options), options, prg_name, &list, &out_list);
    for(j = 0; j < dest_nbands; j++) {
        VAppendAttr(out_list, "image", NULL, VImageRepn, dst_image[j]);
    }
    /* Open and write the output file: */
    if(strcmp(out_filename, "-") == 0)
        out_file = stdout;
    else {
        out_file = fopen(out_filename, "w");
        if(! out_file)
            VError("Failed to open output file %s", out_filename);
    }
    if(!VWriteFile(out_file, out_list) || fclose(out_file))
        VSystemError("error writing output file");
    fprintf(stderr, "\n%s: done.\n", argv[0]);
    return (EXIT_SUCCESS);
}