示例#1
0
void TabDialog::apply() {
  // min und max in gray value table
  if (strlen(VNewString(tablemin->text()))>0 && strlen(VNewString(tablemax->text()))>0) {
    float ymax = (float)selImage->maxwert;
    float ymin = (float)selImage->minwert;
    float ymaxmin = (float)(ymax - ymin);
    float min1 = atof(strtok(VNewString(tablemin->text())," "));
    float max1 = atof(strtok(VNewString(tablemax->text())," "));
    if (min1 > max1) {
      tablemin->setText(tr("%1").arg(selImage->minwert1));
      tablemax->setText(tr("%1").arg(selImage->maxwert1));
    } else {
      selImage->anamean = min1;
      selImage->anaalpha = (float)255.0/(max1 - selImage->anamean);
      int newbrig = (int)rint(stretch*(ymin - selImage->anamean + (ymaxmin - 255.0/selImage->anaalpha)/2.0)/ymaxmin);
      int newhell = (int)rint(log(selImage->anaalpha*ymaxmin/255.0)/log(stretchfact));

      if ((newbrig>=-100 && newbrig<=100) && (newhell>=-100 && newhell<=100)) {
        brig->setValue(newbrig);
	hell->setValue(newhell);
      } else {
	brig->setEnabled( FALSE );
	hell->setEnabled( FALSE );
	lbrigbr->setEnabled( FALSE );
	lwhit->setEnabled( FALSE );
      }
      setMinMaxValue();
      emit newColtype();
    }
  } else {
    tablemin->setText(tr("%1").arg(selImage->minwert1));
    tablemax->setText(tr("%1").arg(selImage->maxwert1));
  }
  emit newColtype();
}
示例#2
0
文件: Attr.c 项目: Rollmops/via
VBoolean VExtractAttr (VAttrList list, VStringConst name,
		       VDictEntry *dict, VRepnKind repn, VPointer value,
		       VBooleanPromoted required)
{
    VAttrListPosn posn;

    /* If the attribute is in the list... */
    if (VLookupAttr (list, name, & posn)) {

	if (value) {

	    /* Get its value: */
	    if (! VGetAttrValue (& posn, dict, repn, value)) {
		VWarning ("VExtractAttr: %s attribute has bad value", name);
		return FALSE;
	    }

	    /* Clone or hide the value if we're about to delete it: */
	    if (repn == VStringRepn)
		* (VString *) value = VNewString (* (VString *) value);
	}

	/* Remove it from the list: */
	VDeleteAttr (& posn);
	return TRUE;
    }

    /* Otherwise complain if the attribute was a required one: */
    if (required)
	VWarning ("VExtractAttr: %s attribute missing", name);
    return ! required;
}
示例#3
0
文件: help.c 项目: Rollmops/via
static void LoadHelpFile (void)
{
    FILE *f;
    size_t len, incr;
    Topic *topic;
    char buf[100];

    ntopics = 0;
    topics = topic = VMalloc (sizeof (Topic) * maxTopics);
    if (! (f = fopen (helpFilename, "r"))) {
	VWarning ("Unable to open help database %s", helpFilename);
	ntopics = 1;
	topic->topic = "(No help topics)";
	topic->text = "(No help text)";
	topic->len = strlen (topic->text);
	return;
    }

    do {
	fgets (buf, sizeof (buf), f);
    } while (! feof (f) && buf[0] != '@');

    while (! feof (f) && ntopics < maxTopics) {
	len = strlen (buf);
	if (buf[len - 1] == '\n')
	    buf[len - 1] = 0;
	topic->topic = VNewString (buf + 1);
	topic->text = NULL;
	len = 0;
	while (1) {
	    fgets (buf, sizeof (buf), f);
	    if (feof (f) || buf[0] == '@')
		break;
	    incr = strlen (buf);
	    topic->text = VRealloc ((XtPointer) topic->text, len + incr + 1);
	    strcpy (topic->text + len, buf);
	    len += incr;
	}
	while (len > 0 && isspace (topic->text[len - 1]))
	    len--;
	topic->text[len] = 0;
	topic->len = len;
	ntopics++;
	topic++;
    }

    fclose (f);
}
示例#4
0
VRepnKind VRegisterType (VStringConst name, VTypeMethods *methods)
{
    VRepnInfoRec *p;

    /* Move the existing type information into a bigger table: */
    if (VRepnInfo == builtin_repn_info) {
        VRepnInfo = VMalloc ((VNRepnKinds + 1) * sizeof (VRepnInfoRec));
        memcpy(VRepnInfo, builtin_repn_info, VNRepnKinds * sizeof (VRepnInfoRec));
    } else
        VRepnInfo =
            VRealloc (VRepnInfo, (nRepnKinds + 1) * sizeof (VRepnInfoRec));

    /* Write the new type's info into the last table entry: */
    p = VRepnInfo + nRepnKinds;
    p->name = VNewString (name);
    p->size = p->precision = p->min_value = p->max_value = 0.0;
    p->methods = methods;

    return nRepnKinds++;
}
示例#5
0
文件: BlockIO.c 项目: Rollmops/lipsia
VAttrList
GetListInfo(VString in_filename, ListInfo *linfo) {
    VAttrList list = NULL;
    VAttrListPosn posn;
    FILE *in_file = NULL;
    VString str, voxel = NULL;
    VRepnKind repn = VShortRepn;
    int ntimesteps, nrows, ncols;
    int id, j, itr, found, nobject, nbands;
    VImageInfo *imageInfo = NULL;
    in_file = VOpenInputFile(in_filename, TRUE);
    if(!in_file)
        VError("error opening file %s", in_filename);
    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));
    itr = ntimesteps = nrows = ncols = 0;
    nobject = nbands = found = id = 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");
        linfo->ntimesteps = linfo->nrows = linfo->ncols = 0;
        if(imageInfo[nbands].repn == VShortRepn) {
            found = 1;
            repn = imageInfo[nbands].repn;
            if(imageInfo[nbands].nbands > ntimesteps)
                ntimesteps = imageInfo[nbands].nbands;
            if(imageInfo[nbands].nrows > nrows)
                nrows = imageInfo[nbands].nrows;
            if(imageInfo[nbands].ncolumns > ncols)
                ncols = imageInfo[nbands].ncolumns;
            if(voxel == NULL)
                voxel = imageInfo[nbands].voxel;
            /* check if slice contains non-zero data */
            linfo->zero[nbands] = 1;
            if(imageInfo[nbands].nrows < 2)
                linfo->zero[nbands] = 0;
            linfo->info[id] = imageInfo[nbands];
            itr = imageInfo[nbands].repetition_time;
            id++;
            nbands++;
        }
        nobject++;
    }
    fclose(in_file);
    if(!found)
        VError(" couldn't find functional data");
    linfo->ntimesteps = ntimesteps;
    linfo->nrows    = nrows;
    linfo->ncols    = ncols;
    linfo->nslices  = id;
    linfo->itr      = itr;
    linfo->repn     = repn;
    linfo->voxel    = voxel;
    linfo->filename = VNewString(in_filename);
    return list;
}
示例#6
0
文件: vcolorglm.c 项目: karda/lipsia
int
main(int argc, char *argv[]) {
    static VArgVector in_files;
    static VString out_filename;
    static VString filename;
    static VShort minval = 0;
    static VFloat fwhm = 4.0;
    static VOptionDescRec  options[] = {
        {"in", VStringRepn, 0, & in_files, VRequiredOpt, NULL, "Input files" },
        {"out", VStringRepn, 1, & out_filename, VRequiredOpt, NULL, "Output file" },
        {"design", VStringRepn, 1, (VPointer) &filename, VRequiredOpt, NULL, "Design file"},
        {
            "fwhm", VFloatRepn, 1, (VPointer) &fwhm, VOptionalOpt, NULL,
            "FWHM of temporal Gaussian filter in seconds"
        },
        {"minval", VShortRepn, 1, (VPointer) &minval, VOptionalOpt, NULL, "Signal threshold"}
    };
    FILE *fp = NULL, *f = NULL;
    VStringConst in_filename;
    VString ifilename;
    VAttrList list = NULL, list1 = NULL;
    VAttrList out_list = NULL, history_list = NULL;
    VAttrListPosn posn;
    VImage design = NULL;
    ListInfo *linfo;
    VLong itr = 0;
    VFloat sigma = 0, tr = 0;
    int  i, n, nimages;
   char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vcolorglm V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /*
    ** parse command line
    */
    if(! VParseCommand(VNumber(options), options, & argc, argv)) {
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    if(argc > 1) {
        VReportBadArgs(argc, argv);
        exit(EXIT_FAILURE);
    }
    /*
    ** read design matrix
    */
    fp = VOpenInputFile(filename, TRUE);
    list1 = VReadFile(fp, NULL);
    if(! list1)
        VError("Error reading design file");
    fclose(fp);
    n = 0;
    for(VFirstAttr(list1, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & design);
        if(VPixelRepn(design) != VFloatRepn /* && VPixelRepn(design) != VDoubleRepn */)
            continue;
        n++;
        break;
    }
    if(n == 0)
        VError(" design matrix not found ");
    /*
    ** get pre-coloring info
    */
    if(VGetAttr(VImageAttrList(design), "repetition_time", NULL, VLongRepn, &itr) != VAttrFound)
        VError(" TR info missing in header");
    tr = (float) itr / 1000.0;
    sigma = 0;
    if(tr > 0.001 && fwhm > 0.001) {
        fprintf(stderr, " TR: %.3f seconds\n", tr);
        sigma = fwhm / 2.35482;
        sigma /= tr;
        if(sigma < 0.1) {
            VWarning(" 'fwhm/sigma' too small (%.3f / %.3f), will be set to zero", fwhm, sigma);
            sigma = 0;
        }
    }
    /*
    ** Read each input file
    */
    nimages = in_files.number;
    linfo = (ListInfo *) VMalloc(sizeof(ListInfo) * nimages);
    for(i = 0; i < nimages; i++) {
        in_filename = ((VStringConst *) in_files.vector)[i];
        ifilename = VNewString(in_filename);
        fprintf(stderr, " file:  %s\n", ifilename);
        list = GetListInfo(ifilename, &linfo[i]);
        /* Create history */
        if(i == 0) {
            history_list = VReadHistory(&list);
            if(history_list == NULL)
                history_list = VCreateAttrList();
            VPrependHistory(VNumber(options), options, prg_name, &history_list);
        }
    }

    /*
    ** GLM
    */
    out_list = VRegression(linfo, nimages, minval, design, sigma, itr);


    /*
    **  Output:
    */
    VPrependAttr(out_list, "history", NULL, VAttrListRepn, history_list);
    f = VOpenOutputFile(out_filename, TRUE);
    if(!f)
        VError(" error opening outout file %s", out_filename);
    if(! VWriteFile(f, out_list))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    return 0;
}
示例#7
0
文件: Attr.c 项目: Rollmops/via
VBoolean VDecodeAttrValue (VStringConst str, VDictEntry *dict,
			   VRepnKind repn, VPointer value)
{
    VLong i_value = 0;
    VDouble f_value = 0.0;
    char *cp = NULL, buf[20];

    /* If a dict is provided, see if str maps to any dict entry keyword,
       substituting the associated value if found: */
    if (dict) {
	dict = VLookupDictKeyword (dict, str);

	/* If there's a dictionary entry, complete it: */
	if (dict && ! dict->svalue) {
	    str = NULL;
	    dict->icached = dict->fcached = TRUE;
	    sprintf (buf, "%ld", (long) dict->ivalue);
	    dict->svalue = VNewString (buf);
	    dict->fvalue = dict->ivalue;
	}
    }

    /* Convert to the internal representation: */
    switch (repn) {

    case VBitRepn:
    case VUByteRepn:
    case VSByteRepn:
    case VShortRepn:
    case VLongRepn:
    case VBooleanRepn:
	if (dict) {
	    if (dict->icached)
		i_value = dict->ivalue;
	    else {
		dict->ivalue = i_value = strtol (dict->svalue, & cp, 0);
		dict->icached = TRUE;
	    }
	} else i_value = strtol (str, & cp, 0);
	break;

    case VFloatRepn:
    case VDoubleRepn:
	if (dict) {
	    if (dict->fcached)
		f_value = dict->fvalue;
	    else {
		dict->fvalue = f_value = strtod (dict->svalue, & cp);
		dict->fcached = TRUE;
	    }
	} else f_value = strtod (str, & cp);
	break;

    case VStringRepn:
	if (dict)
	    str = dict->svalue;
	break;

    default:
	VError ("VDecodeAttrValue: Can't decode to %s", VRepnName (repn));
    }
    if (cp && *cp)
	return FALSE;

    /* Store at *value: */
    switch (repn) {
    case VBitRepn: * (VBit *) value = i_value; break;
    case VUByteRepn: * (VUByte *) value = i_value; break;
    case VSByteRepn: * (VSByte *) value = i_value; break;
    case VShortRepn: * (VShort *) value = i_value; break;
    case VLongRepn: * (VLong *) value = i_value; break;
    case VFloatRepn: * (VFloat *) value = f_value; break;
    case VDoubleRepn: * (VDouble *) value = f_value; break;
    case VBooleanRepn: * (VBoolean *) value = i_value; break;
    case VStringRepn: * (VStringConst *) value = str; break;

    default:
	break;
    }

    return TRUE;
}
示例#8
0
VAttrList
VGetContrast(VAttrList list, gsl_vector_float *con, VShort type) {
    VAttrList out_list;
    int nbands = 0, nrows = 0, ncols = 0, band, row, col;
    VImage src = NULL, dest = NULL, std_image = NULL;
    VImage beta_images[MBETA], res_image = NULL, bcov_image = NULL;
    VString buf = NULL;
    VAttrListPosn posn;
    VString str;
    int    i, nbeta;
    float  t = 0, s = 0, tsigma = 0, z = 0, zmax = 0, zmin = 0;
    float  sigma, var, sum, df;
    float  *ptr1, *ptr2;
    char *constring = NULL;
    gsl_vector_float *beta = NULL, *tmp = NULL;
    gsl_matrix_float *bcov = NULL;
    i = 0;
    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, "BETA") == 0) {
            beta_images[i++] = VCopyImage(src, NULL, VAllBands);
        } else if(strcmp(str, "RES/trRV") == 0) {
            res_image = VCopyImage(src, NULL, VAllBands);
        } else if(strcmp(str, "BCOV") == 0) {
            bcov_image = VCopyImage(src, NULL, VAllBands);
        }
    }
    nbeta  = VImageNRows(bcov_image);
    nbands = VImageNBands(beta_images[0]);
    nrows  = VImageNRows(beta_images[0]);
    ncols  = VImageNColumns(beta_images[0]);
    if(VGetAttr(VImageAttrList(beta_images[0]), "df", NULL, VFloatRepn, &df) != VAttrFound)
        VError(" attribute 'df' not found");
    if(nbeta > MBETA) {
        fprintf(stderr, " number of betas: %d,  maximum number of betas: %d\n", nbeta, MBETA);
        VError(" maximum number of betas is exceeded");
    }
    /*
    ** read contrast vector
    */
    if(nbeta != con->size)
        VError("contrast vector has bad length (%d), correct length is %d", con->size, nbeta);
    fprintf(stderr, " contrast vector:\n");
    char str1[10];
    constring = (char *)VMalloc(sizeof(char) * 10 * nbeta);
    constring[0] = '\0';
    for(i = 0; i < nbeta; i++) {
        fprintf(stderr, "  %.2f", fvget(con, i));
        sprintf(str1, "%1.2f ", fvget(con, i));
        strcat((char *)constring, (const char *)str1);
    }
    fprintf(stderr, "\n");
    /* get variance estimation */
    bcov = gsl_matrix_float_alloc(nbeta, nbeta);
    ptr1 = VImageData(bcov_image);
    ptr2 = bcov->data;
    for(i = 0; i < nbeta * nbeta; i++)
        *ptr2++ = *ptr1++;
    gsl_matrix_float_transpose(bcov);
    tmp   = fmat_x_vector(bcov, con, tmp);
    var   = fskalarproduct(tmp, con);
    sigma = sqrt(var);
    /*
    ** create output data structs
    */
    out_list = VCreateAttrList();
    dest = VCreateImage(nbands, nrows, ncols, VFloatRepn);
    VFillImage(dest, VAllBands, 0);
    VCopyImageAttrs(beta_images[0], dest);
    switch(type) {
    case 0:    /* conimg  */
        buf = VNewString("conimg");
        break;
    case 1:    /* t-image */
        buf = VNewString("tmap");
        break;
    case 2:    /* zmap    */
        buf = VNewString("zmap");
        break;
    default:
        VError(" illegal type");
    }
    fprintf(stderr, " output type: %s\n", buf);
    VSetAttr(VImageAttrList(dest), "modality", NULL, VStringRepn, buf);
    VSetAttr(VImageAttrList(dest), "name", NULL, VStringRepn, buf);
    VSetAttr(VImageAttrList(dest), "contrast", NULL, VStringRepn, constring);
    VAppendAttr(out_list, "image", NULL, VImageRepn, dest);
    if(type == 0) {
        std_image = VCreateImage(nbands, nrows, ncols, VFloatRepn);
        VFillImage(std_image, VAllBands, 0);
        VCopyImageAttrs(beta_images[0], std_image);
        VSetAttr(VImageAttrList(std_image), "modality", NULL, VStringRepn, "std_dev");
        VSetAttr(VImageAttrList(std_image), "name", NULL, VStringRepn, "std_dev");
        VAppendAttr(out_list, "image", NULL, VImageRepn, std_image);
    }
    /*
    ** loop thru image
    */
    zmax = zmin = 0;
    beta = gsl_vector_float_alloc(nbeta);
    for(band = 0; band < nbands; band++) {
        for(row = 0; row < nrows; row++) {
            for(col = 0; col < ncols; col++) {
                t = z = sum = 0;
                ptr1 = beta->data;
                for(i = 0; i < nbeta; i++) {
                    *ptr1++ = VPixel(beta_images[i], band, row, col, VFloat);
                }
                sum  = fskalarproduct(beta, con);
                if(ABS(sum) < 1.0e-10)
                    continue;
                s = VPixel(res_image, band, row, col, VFloat);
                tsigma = sqrt(s) * sigma;
                if(tsigma > 0.00001)
                    t = sum / tsigma;
                else
                    t = 0;
                if(isnan(t) || isinf(t))
                    t = 0;
                switch(type) {
                case 0:    /* conimg  */
                    z = sum;
                    break;
                case 1:    /* t-image */
                    z = t;
                    break;
                case 2:    /* zmap    */
                    z = t2z_approx(t, df);
                    if(z > 30)
                        z = 30;
                    if(sum < 0)
                        z = -z;
                    break;
                default:
                    ;
                }
                if(isnan(z) || isinf(z))
                    z = 0;
                if(z > zmax)
                    zmax = z;
                if(z < zmin)
                    zmin = z;
                VPixel(dest, band, row, col, VFloat) = z;
                if(type == 0)
                    VPixel(std_image, band, row, col, VFloat) = tsigma;
            }
        }
    }
    fprintf(stderr, " min= %.3f,  max= %.3f\n", zmin, zmax);
    return out_list;
}