|
From: Gordon K. <kin...@us...> - 2004-03-30 19:37:24
|
Update of /cvsroot/teem/teem/src/nrrd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6688/nrrd Modified Files: axis.c defaultsNrrd.c enumsNrrd.c formatEPS.c formatNRRD.c histogram.c nrrd.h nrrdEnums.h parseNrrd.c privateNrrd.h reorder.c resampleNrrd.c subset.c superset.c write.c Log Message: Two major changes, which were done simultaneously: 1) Some renamings related to NrrdAxis, nrrdAxisInfo, and so on 2) Addition of the nrrdKind information to the NrrdAxisInfo struct In detail: 1) Some renamings related to NrrdAxis, nrrdAxisInfo, and so on: struct: NrrdAxis --> NrrdAxisInfo (NB: Nrrd struct still has field "axis") functions: nrrdAxisPos() --> nrrdAxisInfoPos() nrrdAxisIdx() --> nrrdAxisInfoIdx() nrrdAxisPosRange() --> nrrdAxisInfoPosRange() nrrdAxisIdxRange() --> nrrdAxisInfoIdxRange() nrrdAxisSpacingSet() --> nrrdAxisInfoSpacingSet() nrrdAxisMinMaxSet() --> nrrdAxisInfoMinMaxSet() Now, ANYTHING having to do with setting, getting, or manipulating the meta-information about the axes starts with "nrrdAxisInfo". The single exception to this is that the Nrrd struct's "axis" field was not renamed to "axisInfo", since this seemed more annoying that it was worth. Also, (this isn't new) ANYTHING having to do the set of axes, the shape of the array, or the per-axis ordering of samples, starts with "nrrdAxes". The nrrdAxes functions are NOT merely for manipulating the per-axis meta information-- something about the array as a whole, or the set of axes as a whole, is changing. Yes, this means that there's a function called "nrrdAxesInsert", even though it only inserts a single axis, but I figured the consistency generated by strict adherence to the nrrdAxes and nrrdAxisInfo prefixes would be better in the long run. 2) Addition of the nrrdKind information to the NrrdAxisInfo struct This is nrrd's latest and probably most dangerous step towards putting real semantic information in the array representation (that is, the "nearly raw" philosophy is getting stretched). The best way to think about this is that its a *hint*: an extra bit of information, kind of like the label or the unit, that you may want to associated with the axis, and which has a sufficiently general nature to warrent direct representation. So, new to the (newly renamed) NrrdAxisInfo struct: int kind; /* what kind of information is along this axis (from the nrrdKind* enum) */ Accordingly, there is change to the file format, which of course means that the magic is once again incremented. If you write a nrrd with known kinds on any axis, the magic will be "NRRD0003". The new kinds field looks like (for-example) kinds: 3-color domain domain for an RGB image. Like other per-axis fields, its specification is plural (its "kinds:", not "kind:"), and like centering, you use "???" to mean, "I don't know", for example: kinds: ??? domain domain To make this hint more useful, there's a new function nrrdKindSize() which returns what nrrd thinks is the suggested axis size for the different nrrdKind's. This function will return 0 to indicate "I have no advice for you on how big this axis should be". The reason for using 0 instead of -1 is that someday nrrd may change the axis size type from int to unsigned int. To offer some control of the nrrdKind behavior, there is a new global "state" variable: nrrdStateKindNoop. Currently, this is AIR_TRUE by defaul. You can set it to AIR_FALSE to enable some minimal cleverness on the part of nrrd. The nature of that minimal cleverness is almost certainly likely to change with time. Due to the nature of nrrdAxisInfoCopy, anything which doesn't explicitly ask the axis information NOT to be copied, will have it be copied. For example, nrrdSlice will propogate through the kinds on the axes that it didn't touch, same with nrrdAxesPermute, and the like. Regardless of NrrdKindStateNoop, the output of these functions will set nrrdKindUnknown on all the axes that experienced a non-trivial change: nrrdAxesSplit, nrrdAxesMerge, nrrdReshape, nrrdReshape_nva, nrrdUnblock, nrrdJoin, nrrdApply1DLut, nrrdApply1DRegMap, and nrrdApply1DIrregMap. These functions respect nrrdKindStateNoop: nrrdCrop, nrrdPad, nrrdShuffle, nrrdFlip, nrrdSpatialResample: if (nrrdKindStateNoop) { If the axis operated on was not a nrrdKindDomain or nrrdKindList, the resulting kind is nrrdKindUnknown Else, the resulting kind is the same as the input kind. This is implemented through _nrrdKindAltered() } else { output kind is a copy of the input kind } nrrdHisto, nrrdHistoAxis, nrrdHistoJoint: if (nrrdKindStateNoop) { histogram axes are nrrdKindDomain } else { histogram axes are nrrdKindUnknown } nrrdAxisInsert: if (nrrdKindStateNoop) { new axis is nrrdKindStub } else { new axis is nrrdKindUnknown } For the record, this is what this change entailed: added: - global int nrrdStateKindNoop - nrrdKindSize() - airEnum *nrrdKind (maps between strings like "3color" and nrrdKind* values) - NRRD_KIND_MAX #define augmented: - NrrdAxisInfo struct (now has "kind" field) - _nrrdFieldInteresting(), _nrrdSprintFieldInfo(), _nrrdFormatNRRD_write() with things relating to new field ("kinds:") and magic ("NRRD0003") - _nrrdReadNrrdParseInfo[] parser callback, with new _nrrdReadNrrdParse_kinds() - airEnum *nrrdField - nrrdAxisInfo C enum (for passing to nrrdAxisInfo{Set,Get}) - nrrdField* C enum - nrrdStateGetenv(): looks for NRRD_STATE_KIND_NOOP" environment variable One annoying bit: I didn't add a new flag to "unu make" to learn the axis kinds because I *can't*. This is a basic limitation in hest which is gotten pretty annoying: there is direct way to see if an option was given on the command line or not. Every option has to have a value supplied, either via the command-line or via the default value string, but once its all been parsed, you don't know where it came from, and nor can you tell hest "this option is really really optional, there is no default, and its okay if the user never gives you a value." This will only be fixed with a hest re-write. Index: reorder.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/reorder.c,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** reorder.c 13 Mar 2004 20:03:10 -0000 1.56 --- reorder.c 30 Mar 2004 19:25:09 -0000 1.57 *************** *** 63,66 **** --- 63,70 ---- /* the ONLY thing we can say about the new axis is its size */ _nrrdAxisInfoInit(&(nout->axis[ax])); + if (!nrrdStateKindNoop) { + /* except maybe the kind */ + nout->axis[ax].kind = nrrdKindStub; + } nout->axis[ax].size = 1; if (nrrdContentSet(nout, func, nin, "%d", ax)) { *************** *** 364,367 **** --- 368,372 ---- /* the min and max along the shuffled axis are now meaningless */ nout->axis[axis].min = nout->axis[axis].max = AIR_NAN; + nout->axis[axis].kind = _nrrdKindAltered(nin->axis[axis].kind); nrrdPeripheralCopy(nout, nin); strcpy(buff1, ""); Index: parseNrrd.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/parseNrrd.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** parseNrrd.c 7 Jan 2004 15:34:30 -0000 1.21 --- parseNrrd.c 30 Mar 2004 19:25:09 -0000 1.22 *************** *** 247,250 **** --- 247,283 ---- } + int + _nrrdReadNrrdParse_kinds (Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + char me[]="_nrrdReadNrrdParse_kinds", err[AIR_STRLEN_MED]; + int i; + char *tok; + char *info, *last; + + info = nio->line + nio->pos; + _CHECK_HAVE_DIM; + for (i=0; i<=nrrd->dim-1; i++) { + tok = airStrtok(!i ? info : NULL, _nrrdFieldSep, &last); + if (!tok) { + sprintf(err, "%s: couldn't extract string for kind %d of %d", + me, i+1, nrrd->dim); + biffMaybeAdd(NRRD, err, useBiff); return 1; + } + if (!strcmp(tok, NRRD_UNKNOWN)) { + nrrd->axis[i].kind = nrrdKindUnknown; + continue; + } + if (!(nrrd->axis[i].kind = airEnumVal(nrrdKind, tok))) { + sprintf(err, "%s: couldn't parse \"%s\" kind %d of %d", + me, tok, i+1, nrrd->dim); + biffMaybeAdd(NRRD, err, useBiff); return 1; + } + /* + fprintf(stderr, "!%s: nrrd->axis[%d].kind = %d\n", + me, i, nrrd->axis[i].kind); + */ + } + return 0; + } + char * _nrrdGetQuotedString(char **hP, int useBiff) { *************** *** 577,580 **** --- 610,614 ---- _nrrdReadNrrdParse_axis_maxs, _nrrdReadNrrdParse_centers, + _nrrdReadNrrdParse_kinds, _nrrdReadNrrdParse_labels, _nrrdReadNrrdParse_units, Index: axis.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/axis.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** axis.c 13 Mar 2004 20:03:10 -0000 1.6 --- axis.c 30 Mar 2004 19:25:09 -0000 1.7 *************** *** 24,28 **** void ! _nrrdAxisInfoInit(NrrdAxis *axis) { if (axis) { --- 24,28 ---- void ! _nrrdAxisInfoInit(NrrdAxisInfo *axis) { if (axis) { *************** *** 33,36 **** --- 33,37 ---- axis->unit = airFree(axis->unit); axis->center = nrrdCenterUnknown; + axis->kind = nrrdKindUnknown; } } *************** *** 40,44 **** nrrdAxisInfo *axis; ! axis = calloc(1, sizeof(NrrdAxis)); axis->label = NULL; axis->unit = NULL; --- 41,45 ---- nrrdAxisInfo *axis; ! axis = calloc(1, sizeof(NrrdAxisInfo)); axis->label = NULL; axis->unit = NULL; *************** *** 49,54 **** } ! NrrdAxis * ! nrrdAxisInfoNix(NrrdAxis *axis) { if (axis) { --- 50,55 ---- } ! NrrdAxisInfo * ! nrrdAxisInfoNix(NrrdAxisInfo *axis) { if (axis) { *************** *** 63,68 **** /* ------------------------------------------------------------ */ void ! _nrrdAxisInfoCopy(NrrdAxis *dest, const NrrdAxis *src, int bitflag) { if (!(NRRD_AXIS_INFO_SIZE_BIT & bitflag)) { --- 64,142 ---- /* ------------------------------------------------------------ */ + + /* + ******** nrrdKindSize + ** + ** returns suggested size (length) of an axis with the given kind, or, + ** 0 if there is no suggested size, or the kind was invalid + */ + int + nrrdKindSize(int kind) { + char me[]="nrrdKindSize"; + int ret; + + if (!( AIR_IN_OP(nrrdKindUnknown, kind, nrrdKindLast) )) { + /* they gave us invalid or unknown kind */ + return 0; + } + + switch (kind) { + case nrrdKindDomain: + case nrrdKindList: + ret = 0; + break; + case nrrdKindStub: + case nrrdKindScalar: + ret = 1; + break; + case nrrdKindComplex: + ret = 2; + break; + case nrrdKind3Color: + case nrrdKind3Vector: + case nrrdKind3Normal: + ret = 3; + break; + case nrrdKind4Color: + case nrrdKind4Vector: + ret = 4; + break; + case nrrdKind6Tensor: + ret = 6; + break; + case nrrdKind7Tensor: + ret = 7; + break; + case nrrdKind9Tensor: + case nrrdKind9Matrix: + ret = 9; + break; + default: + fprintf(stderr, "%s: PANIC: nrrdKind %d not implemented!\n", me, kind); + exit(1); + } + + return ret; + } + + int + _nrrdKindAltered(int kindIn) { + int kindOut; + + if (nrrdStateKindNoop) { + kindOut = nrrdKindUnknown; + } else { + if (nrrdKindDomain == kindIn + || nrrdKindList == kindIn) { + kindOut = kindIn; + } else { + kindOut = nrrdKindUnknown; + } + } + return kindOut; + } + void ! _nrrdAxisInfoCopy(NrrdAxisInfo *dest, const NrrdAxisInfo *src, int bitflag) { if (!(NRRD_AXIS_INFO_SIZE_BIT & bitflag)) { *************** *** 81,84 **** --- 155,161 ---- dest->center = src->center; } + if (!(NRRD_AXIS_INFO_KIND_BIT & bitflag)) { + dest->kind = src->kind; + } if (!(NRRD_AXIS_INFO_LABEL_BIT & bitflag)) { if (dest->label != src->label) { *************** *** 184,187 **** --- 261,267 ---- nrrd->axis[d].center = info.I[d]; break; + case nrrdAxisInfoKind: + nrrd->axis[d].kind = info.I[d]; + break; case nrrdAxisInfoLabel: nrrd->axis[d].label = airFree(nrrd->axis[d].label); *************** *** 226,229 **** --- 306,310 ---- break; case nrrdAxisInfoCenter: + case nrrdAxisInfoKind: info.I[d] = va_arg(ap, int); /* *************** *** 304,307 **** --- 385,391 ---- info.I[d] = nrrd->axis[d].center; break; + case nrrdAxisInfoKind: + info.I[d] = nrrd->axis[d].kind; + break; case nrrdAxisInfoLabel: /* note airStrdup()! */ *************** *** 351,354 **** --- 435,439 ---- break; case nrrdAxisInfoCenter: + case nrrdAxisInfoKind: *((int*)ptr) = info.I[d]; /* printf("!%s: got int[%d] = %d\n", *************** *** 405,409 **** /* ! ******** nrrdAxisPos() ** ** given a nrrd, an axis, and a (floating point) index space position, --- 490,494 ---- /* ! ******** nrrdAxisInfoPos() ** ** given a nrrd, an axis, and a (floating point) index space position, *************** *** 414,418 **** */ double ! nrrdAxisPos(const Nrrd *nrrd, int ax, double idx) { int center, size; double min, max; --- 499,503 ---- */ double ! nrrdAxisInfoPos(const Nrrd *nrrd, int ax, double idx) { int center, size; double min, max; *************** *** 430,434 **** /* ! ******** nrrdAxisIdx() ** ** given a nrrd, an axis, and a (floating point) world space position, --- 515,519 ---- /* ! ******** nrrdAxisInfoIdx() ** ** given a nrrd, an axis, and a (floating point) world space position, *************** *** 439,443 **** */ double ! nrrdAxisIdx(const Nrrd *nrrd, int ax, double pos) { int center, size; double min, max; --- 524,528 ---- */ double ! nrrdAxisInfoIdx(const Nrrd *nrrd, int ax, double pos) { int center, size; double min, max; *************** *** 455,459 **** /* ! ******** nrrdAxisPosRange() ** ** given a nrrd, an axis, and two (floating point) index space positions, --- 540,544 ---- /* ! ******** nrrdAxisInfoPosRange() ** ** given a nrrd, an axis, and two (floating point) index space positions, *************** *** 462,468 **** */ void ! nrrdAxisPosRange(double *loP, double *hiP, ! const Nrrd *nrrd, int ax, ! double loIdx, double hiIdx) { int center, size, flip = 0; double min, max, tmp; --- 547,553 ---- */ void ! nrrdAxisInfoPosRange(double *loP, double *hiP, ! const Nrrd *nrrd, int ax, ! double loIdx, double hiIdx) { int center, size, flip = 0; double min, max, tmp; *************** *** 496,500 **** /* ! ******** nrrdAxisIdxRange() ** ** given a nrrd, an axis, and two (floating point) world space positions, --- 581,585 ---- /* ! ******** nrrdAxisInfoIdxRange() ** ** given a nrrd, an axis, and two (floating point) world space positions, *************** *** 513,519 **** */ void ! nrrdAxisIdxRange(double *loP, double *hiP, ! const Nrrd *nrrd, int ax, ! double loPos, double hiPos) { int center, size, flip = 0; double min, max, tmp; --- 598,604 ---- */ void ! nrrdAxisInfoIdxRange(double *loP, double *hiP, ! const Nrrd *nrrd, int ax, ! double loPos, double hiPos) { int center, size, flip = 0; double min, max, tmp; *************** *** 552,556 **** void ! nrrdAxisSpacingSet(Nrrd *nrrd, int ax) { int sign; double min, max, tmp; --- 637,641 ---- void ! nrrdAxisInfoSpacingSet(Nrrd *nrrd, int ax) { int sign; double min, max, tmp; *************** *** 584,588 **** void ! nrrdAxisMinMaxSet(Nrrd *nrrd, int ax, int defCenter) { int center; double spacing; --- 669,673 ---- void ! nrrdAxisInfoMinMaxSet(Nrrd *nrrd, int ax, int defCenter) { int center; double spacing; Index: superset.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/superset.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** superset.c 7 Jan 2004 15:34:30 -0000 1.15 --- superset.c 30 Mar 2004 19:25:09 -0000 1.16 *************** *** 402,407 **** } for (d=0; d<dim; d++) { ! nrrdAxisPosRange(&(nout->axis[d].min), &(nout->axis[d].max), ! nin, d, min[d], max[d]); } strcpy(buff1, ""); --- 402,408 ---- } for (d=0; d<dim; d++) { ! nrrdAxisInfoPosRange(&(nout->axis[d].min), &(nout->axis[d].max), ! nin, d, min[d], max[d]); ! nout->axis[d].kind = _nrrdKindAltered(nin->axis[d].kind); } strcpy(buff1, ""); Index: resampleNrrd.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/resampleNrrd.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** resampleNrrd.c 13 Mar 2004 20:03:10 -0000 1.20 --- resampleNrrd.c 30 Mar 2004 19:25:09 -0000 1.21 *************** *** 81,85 **** /* set the min/max for this axis if not already set to something */ if (!( AIR_EXISTS(nin->axis[d].min) && AIR_EXISTS(nin->axis[d].max) )) ! nrrdAxisMinMaxSet(nin, d, nrrdDefCenter); info->min[d] = nin->axis[d].min; info->max[d] = nin->axis[d].max; --- 81,85 ---- /* set the min/max for this axis if not already set to something */ if (!( AIR_EXISTS(nin->axis[d].min) && AIR_EXISTS(nin->axis[d].max) )) ! nrrdAxisInfoMinMaxSet(nin, d, nrrdDefCenter); info->min[d] = nin->axis[d].min; info->max[d] = nin->axis[d].max; *************** *** 795,812 **** airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopOnError); nrrdAxisInfoCopy(nout, nin, NULL, ! (NRRD_AXIS_INFO_SIZE_BIT | ! NRRD_AXIS_INFO_MIN_BIT | ! NRRD_AXIS_INFO_MAX_BIT | ! NRRD_AXIS_INFO_SPACING_BIT)); for (d=0; d<dim; d++) { if (info->kernel[d]) { nout->axis[d].min = info->min[d]; nout->axis[d].max = info->max[d]; nout->axis[d].spacing = nin->axis[d].spacing/ratios[d]; } else { nout->axis[d].min = nin->axis[d].min; nout->axis[d].max = nin->axis[d].max; nout->axis[d].spacing = nin->axis[d].spacing; } } /* HEY: need to create textual representation of resampling parameters */ --- 795,819 ---- airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopOnError); nrrdAxisInfoCopy(nout, nin, NULL, ! (NRRD_AXIS_INFO_SIZE_BIT ! | NRRD_AXIS_INFO_MIN_BIT ! | NRRD_AXIS_INFO_MAX_BIT ! | NRRD_AXIS_INFO_SPACING_BIT ! | NRRD_AXIS_INFO_KIND_BIT)); for (d=0; d<dim; d++) { + fprintf(stderr, "%s: nin->axis[%d].kind = %s\n", me, d, + airEnumStr(nrrdKind, nin->axis[d].kind)); if (info->kernel[d]) { nout->axis[d].min = info->min[d]; nout->axis[d].max = info->max[d]; nout->axis[d].spacing = nin->axis[d].spacing/ratios[d]; + nout->axis[d].kind = _nrrdKindAltered(nin->axis[d].kind); } else { nout->axis[d].min = nin->axis[d].min; nout->axis[d].max = nin->axis[d].max; nout->axis[d].spacing = nin->axis[d].spacing; + nout->axis[d].kind = nin->axis[d].kind; } + fprintf(stderr, "%s: nout->axis[%d].kind = %s\n", me, d, + airEnumStr(nrrdKind, nout->axis[d].kind)); } /* HEY: need to create textual representation of resampling parameters */ Index: defaultsNrrd.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/defaultsNrrd.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** defaultsNrrd.c 7 Jan 2004 15:34:30 -0000 1.15 --- defaultsNrrd.c 30 Mar 2004 19:25:09 -0000 1.16 *************** *** 70,73 **** --- 70,74 ---- /* there is no sane reason to change this default initialization */ int nrrdStateKeyValueReturnInternalPointers = AIR_FALSE; + int nrrdStateKindNoop = AIR_TRUE; /* should the acceptance (or not) of malformed NRRD header fields *************** *** 99,102 **** --- 100,107 ---- int valI; + if ((envS = getenv("NRRD_STATE_KIND_NOOP")) + && (-1 != (valI = airEnumVal(airBool, envS)))) { + nrrdStateKindNoop = valI; + } if ((envS = getenv("NRRD_STATE_VERBOSE_IO")) && (-1 != (valI = airEnumVal(airBool, envS)))) { Index: enumsNrrd.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/enumsNrrd.c,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** enumsNrrd.c 30 Mar 2004 03:26:12 -0000 1.31 --- enumsNrrd.c 30 Mar 2004 19:25:09 -0000 1.32 *************** *** 270,273 **** --- 270,360 ---- nrrdCenter = &_nrrdCenter_enum; + /* ------------------------ nrrdKind ------------------------- */ + + + char + _nrrdKindStr[NRRD_KIND_MAX+1][AIR_STRLEN_SMALL] = { + "(unknown_kind)", + "domain", + "list", + "stub", + "scalar", + "complex", + "3-color", + "4-color", + "3-vector", + "3-normal", + "6-tensor", + "7-tensor", + "9-tensor", + "9-matrix" + }; + + char + _nrrdKindDesc[NRRD_KIND_MAX+1][AIR_STRLEN_MED] = { + "unknown kind", + "a domain variable of the function which the nrrd samples", + "a list of attributes; it makes no sense to resample along these", + "a place-holder axis with a single sample", + "axis used to indicate that the nrrd contains a scalar value", + "real and imaginary parts of a value", + "any 3-component color value", + "any 4-component color value", + "any 3-element vector", + "a 3-element vector which is assumed normalized", + "any 4-element vector", + "6 unique elements of a symmetric tensor", + "\"confidence\" plus 6 unique elements of a symmetric tensor", + "9 elements of a 3x3 tensor", + "9 elements of a 3x3 matrix" + }; + + char + _nrrdKindStr_Eqv[][AIR_STRLEN_SMALL] = { + "domain", + "list", + "stub", + "scalar", + "complex", + "3-color", "3color", + "4-color", "4color", + "3-vector", "3vector", + "3-normal", "3normal", + "6-tensor", "6tensor", + "7-tensor", "7tensor", + "9-tensor", "9tensor", + "9-matrix", "9matrix", + "" + }; + + int + _nrrdKindVal_Eqv[] = { + nrrdKindDomain, + nrrdKindList, + nrrdKindStub, + nrrdKindScalar, + nrrdKindComplex, + nrrdKind3Color, nrrdKind3Color, + nrrdKind4Color, nrrdKind4Color, + nrrdKind3Vector, nrrdKind3Vector, + nrrdKind3Normal, nrrdKind3Normal, + nrrdKind6Tensor, nrrdKind6Tensor, + nrrdKind7Tensor, nrrdKind7Tensor, + nrrdKind9Tensor, nrrdKind9Tensor, + nrrdKind9Matrix, nrrdKind9Matrix + }; + + airEnum + _nrrdKind_enum = { + "kind", + NRRD_KIND_MAX, + _nrrdKindStr, NULL, + _nrrdKindDesc, + _nrrdKindStr_Eqv, _nrrdKindVal_Eqv, + AIR_FALSE + }; + airEnum * + nrrdKind = &_nrrdKind_enum; + /* ------------------------ nrrdField ------------------------- */ *************** *** 286,289 **** --- 373,377 ---- "axis maxs", "centers", + "kinds", "labels", "units", *************** *** 314,317 **** --- 402,406 ---- "list of maximum positions associated with each axis", "list of sample centerings for each axis", + "list of kinds for each axis", "list of short descriptions for each axis", "list of units in which each axes' spacing is measured", *************** *** 341,344 **** --- 430,434 ---- "axis maxs", "axismaxs", "centers", + "kinds", "labels", "units", *************** *** 369,372 **** --- 459,463 ---- nrrdField_axis_maxs, nrrdField_axis_maxs, nrrdField_centers, + nrrdField_kinds, nrrdField_labels, nrrdField_units, Index: write.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/write.c,v retrieving revision 1.89 retrieving revision 1.90 diff -C2 -d -r1.89 -r1.90 *** write.c 15 Mar 2004 03:07:41 -0000 1.89 --- write.c 30 Mar 2004 19:25:09 -0000 1.90 *************** *** 261,264 **** --- 261,269 ---- } break; + case nrrdField_kinds: + for (d=0; d<nrrd->dim; d++) { + ret |= (nrrdKindUnknown != nrrd->axis[d].kind); + } + break; case nrrdField_labels: for (d=0; d<nrrd->dim; d++) { *************** *** 414,417 **** --- 419,433 ---- } break; + case nrrdField_kinds: + *strP = malloc(fslen + D*10); + sprintf(*strP, "%s%s:", prefix, fs); + for (i=0; i<D; i++) { + sprintf(buff, " %s", + (nrrd->axis[i].kind + ? airEnumStr(nrrdKind, nrrd->axis[i].kind) + : NRRD_UNKNOWN)); + strcat(*strP, buff); + } + break; case nrrdField_labels: fdlen = 0; Index: privateNrrd.h =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/privateNrrd.h,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** privateNrrd.h 7 Jan 2004 15:34:30 -0000 1.30 --- privateNrrd.h 30 Mar 2004 19:25:09 -0000 1.31 *************** *** 107,113 **** /* axis.c */ ! extern void _nrrdAxisInfoCopy(NrrdAxis *dest, const NrrdAxis *src, int bitflag); ! extern void _nrrdAxisInfoInit(NrrdAxis *axis); extern int _nrrdCenter(int center); extern int _nrrdCenter2(int center, int def); --- 107,114 ---- /* axis.c */ ! extern int _nrrdKindAltered(int kindIn); ! extern void _nrrdAxisInfoCopy(NrrdAxisInfo *dest, const NrrdAxisInfo *src, int bitflag); ! extern void _nrrdAxisInfoInit(NrrdAxisInfo *axis); extern int _nrrdCenter(int center); extern int _nrrdCenter2(int center, int def); Index: formatNRRD.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/formatNRRD.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** formatNRRD.c 13 Mar 2004 20:03:10 -0000 1.6 --- formatNRRD.c 30 Mar 2004 19:25:09 -0000 1.7 *************** *** 24,27 **** --- 24,28 ---- #define MAGIC1 "NRRD0001" #define MAGIC2 "NRRD0002" + #define MAGIC3 "NRRD0003" int *************** *** 60,63 **** --- 61,65 ---- || !strcmp(MAGIC1, nio->line) || !strcmp(MAGIC2, nio->line) + || !strcmp(MAGIC3, nio->line) ); } *************** *** 330,337 **** } } ! ! /* currently, which magic we use depends only on whether there are ! key/value pairs */ ! fprintf(file, "%s\n", nrrdKeyValueSize(nrrd) ? MAGIC2 : MAGIC1); /* this is where the majority of the header printing happens */ --- 332,343 ---- } } ! ! /* we try to use the oldest format that will old the nrrd */ ! fprintf(file, "%s\n", ! (_nrrdFieldInteresting(nrrd, nio, nrrdField_kinds) ! ? MAGIC3 ! : (nrrdKeyValueSize(nrrd) ! ? MAGIC2 ! : MAGIC1))); /* this is where the majority of the header printing happens */ Index: formatEPS.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/formatEPS.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** formatEPS.c 7 Jan 2004 15:34:30 -0000 1.4 --- formatEPS.c 30 Mar 2004 19:25:09 -0000 1.5 *************** *** 161,164 **** --- 161,171 ---- fprintf(file, "%%%%Page: 1 1\n"); fprintf(file, "gsave\n"); + fprintf(file, "%g %g moveto\n", minX, minY); + fprintf(file, "%g %g lineto\n", maxX, minY); + fprintf(file, "%g %g lineto\n", maxX, maxY); + fprintf(file, "%g %g lineto\n", minX, maxY); + fprintf(file, "closepath\n"); + fprintf(file, "clip\n"); + fprintf(file, "gsave newpath\n"); fprintf(file, "%g %g translate\n", minX, minY); fprintf(file, "%g %g scale\n", sx*scale, sy*scale); *************** *** 172,175 **** --- 179,183 ---- fprintf(file, "\n"); fprintf(file, "grestore\n"); + fprintf(file, "grestore\n"); airMopError(mop); Index: histogram.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/histogram.c,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** histogram.c 13 Mar 2004 20:03:10 -0000 1.49 --- histogram.c 30 Mar 2004 19:25:09 -0000 1.50 *************** *** 140,143 **** --- 140,146 ---- nout->axis[0].label = airFree(nout->axis[0].label); nout->axis[0].label = airStrdup(nout->content); + if (!nrrdStateKindNoop) { + nout->axis[0].kind = nrrdKindDomain; + } airMopOkay(mop); *************** *** 253,257 **** if (!E) E |= nrrdCommentAdd(nout, cmt); sprintf(cmt, "max hits: %g, in bin %d, around value %g\n", ! maxhits, maxhitidx, nrrdAxisPos(nout, 0, maxhitidx)); if (!E) E |= nrrdCommentAdd(nout, cmt); if (!E) E |= nrrdContentSet(nout, func, nin, "%d", sy); --- 256,260 ---- if (!E) E |= nrrdCommentAdd(nout, cmt); sprintf(cmt, "max hits: %g, in bin %d, around value %g\n", ! maxhits, maxhitidx, nrrdAxisInfoPos(nout, 0, maxhitidx)); if (!E) E |= nrrdCommentAdd(nout, cmt); if (!E) E |= nrrdContentSet(nout, func, nin, "%d", sy); *************** *** 351,354 **** --- 354,360 ---- nout->axis[ax].label = NULL; } + if (!nrrdStateKindNoop) { + nout->axis[ax].kind = nrrdKindDomain; + } /* the skinny: we traverse the input samples in linear order, and *************** *** 492,495 **** --- 498,504 ---- nout->axis[d].max = range[d]->max; nout->axis[d].center = nrrdCenterCell; + if (!nrrdStateKindNoop) { + nout->axis[d].kind = nrrdKindDomain; + } if (nin[d]->content) { hadContent = 1; Index: nrrdEnums.h =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/nrrdEnums.h,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** nrrdEnums.h 30 Mar 2004 03:26:12 -0000 1.42 --- nrrdEnums.h 30 Mar 2004 19:25:09 -0000 1.43 *************** *** 61,65 **** nrrdFormatTypeUnknown, nrrdFormatTypeNRRD, /* 1: basic nrrd format (associated with any of ! the magics starting with "NRRD" */ nrrdFormatTypePNM, /* 2: PNM image */ nrrdFormatTypePNG, /* 3: PNG image */ --- 61,65 ---- nrrdFormatTypeUnknown, nrrdFormatTypeNRRD, /* 1: basic nrrd format (associated with any of ! the magics starting with "NRRD") */ nrrdFormatTypePNM, /* 2: PNM image */ nrrdFormatTypePNG, /* 3: PNG image */ *************** *** 173,176 **** --- 173,206 ---- /* + ******** nrrdKind enum + ** + ** The very cautious (and last?) step nrrd takes towards sementics. + ** + ** More of these may be added in the future, as when nrrd supports bricking. + ** + ** NB: The nrrdKindSize() function returns the suggested length for these. + */ + enum { + nrrdKindUnknown, + nrrdKindDomain, /* 1: "It makes sense to resample along here" */ + nrrdKindList, /* 2: "It makes NO sense to resample along here" */ + nrrdKindStub, /* 3: axis with one sample */ + nrrdKindScalar, /* 4: same as a stub */ + nrrdKindComplex, /* 5: real and imaginary components of a number */ + nrrdKind3Color, /* 6: ANY 3-component color value */ + nrrdKind4Color, /* 7: ANY 4-component color value */ + nrrdKind3Vector, /* 8: any 3-vector */ + nrrdKind3Normal, /* 9: 3-vectors which are assumed normalized */ + nrrdKind4Vector, /* 10: any 4-vector */ + nrrdKind6Tensor, /* 11: the 6 unique elements of a symmetric 3x3 tensor */ + nrrdKind7Tensor, /* 12: some scalar "confidence" or "valid" value, and + the 6 unique elements of a symmetric 3x3 tensor */ + nrrdKind9Tensor, /* 13: all 9 elements of a 3x3 tensor */ + nrrdKind9Matrix, /* 14: all 9 elements of a 3x3 matrix */ + nrrdKindLast + }; + #define NRRD_KIND_MAX 14 + + /* ******** nrrdAxisInfo enum ** *************** *** 189,200 **** nrrdAxisInfoCenter, /* 5: cell vs. node */ #define NRRD_AXIS_INFO_CENTER_BIT (1<<5) ! nrrdAxisInfoLabel, /* 6: string describing the axis */ ! #define NRRD_AXIS_INFO_LABEL_BIT (1<<6) ! nrrdAxisInfoUnit, /* 7: string identifying units */ ! #define NRRD_AXIS_INFO_UNIT_BIT (1<<7) nrrdAxisInfoLast }; ! #define NRRD_AXIS_INFO_MAX 7 ! #define NRRD_AXIS_INFO_ALL ((1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)) #define NRRD_AXIS_INFO_NONE 0 --- 219,233 ---- nrrdAxisInfoCenter, /* 5: cell vs. node */ #define NRRD_AXIS_INFO_CENTER_BIT (1<<5) ! nrrdAxisInfoKind, /* 6: from the nrrdKind* enum */ ! #define NRRD_AXIS_INFO_KIND_BIT (1<<6) ! nrrdAxisInfoLabel, /* 7: string describing the axis */ ! #define NRRD_AXIS_INFO_LABEL_BIT (1<<7) ! nrrdAxisInfoUnit, /* 8: string identifying units */ ! #define NRRD_AXIS_INFO_UNIT_BIT (1<<8) nrrdAxisInfoLast }; ! #define NRRD_AXIS_INFO_MAX 8 ! #define NRRD_AXIS_INFO_ALL \ ! ((1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)) #define NRRD_AXIS_INFO_NONE 0 *************** *** 227,245 **** nrrdField_axis_maxs, /* 10 */ nrrdField_centers, /* 11 */ ! nrrdField_labels, /* 12 */ ! nrrdField_units, /* 13 */ ! nrrdField_min, /* 14 */ ! nrrdField_max, /* 15 */ ! nrrdField_old_min, /* 16 */ ! nrrdField_old_max, /* 17 */ ! nrrdField_data_file, /* 18 */ ! nrrdField_endian, /* 19 */ ! nrrdField_encoding, /* 20 */ ! nrrdField_line_skip, /* 21 */ ! nrrdField_byte_skip, /* 22 */ ! nrrdField_keyvalue, /* 23 */ nrrdField_last }; ! #define NRRD_FIELD_MAX 23 /* --- 260,279 ---- nrrdField_axis_maxs, /* 10 */ nrrdField_centers, /* 11 */ ! nrrdField_kinds, /* 12 */ ! nrrdField_labels, /* 13 */ ! nrrdField_units, /* 14 */ ! nrrdField_min, /* 15 */ ! nrrdField_max, /* 16 */ ! nrrdField_old_min, /* 17 */ ! nrrdField_old_max, /* 18 */ ! nrrdField_data_file, /* 19 */ ! nrrdField_endian, /* 20 */ ! nrrdField_encoding, /* 21 */ ! nrrdField_line_skip, /* 22 */ ! nrrdField_byte_skip, /* 23 */ ! nrrdField_keyvalue, /* 24 */ nrrdField_last }; ! #define NRRD_FIELD_MAX 24 /* Index: nrrd.h =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/nrrd.h,v retrieving revision 1.136 retrieving revision 1.137 diff -C2 -d -r1.136 -r1.137 *** nrrd.h 30 Mar 2004 03:26:12 -0000 1.136 --- nrrd.h 30 Mar 2004 19:25:09 -0000 1.137 *************** *** 70,77 **** spacing) should be taken to be significant at any time. */ ! int center; /* cell vs. node centering */ char *label; /* short info string for each axis */ char *unit; /* short string for identifying units */ ! } NrrdAxis; /* --- 70,80 ---- spacing) should be taken to be significant at any time. */ ! int center; /* cell vs. node centering (value should be ! one of nrrdCenter{Unknown,Node,Cell} */ ! int kind; /* what kind of information is along this ! axis (from the nrrdKind* enum) */ char *label; /* short info string for each axis */ char *unit; /* short string for identifying units */ ! } NrrdAxisInfo; /* *************** *** 86,101 **** ** or at the time that the nrrd is wrapped around an existing array */ ! void *data; /* the data in memory */ ! int type; /* a value from the nrrdType enum */ ! int dim; /* what is dimension of data */ /* ** All per-axis specific information */ ! NrrdAxis axis[NRRD_DIM_MAX]; /* axis[0] is the fastest axis in the scan- ! line ordering, the one who's coordinates ! change the fastest as the elements are ! accessed in the order in which they appear ! in memory */ /* --- 89,104 ---- ** or at the time that the nrrd is wrapped around an existing array */ ! void *data; /* the data in memory */ ! int type; /* a value from the nrrdType enum */ ! int dim; /* what is dimension of data */ /* ** All per-axis specific information */ ! NrrdAxisInfo axis[NRRD_DIM_MAX]; /* axis[0] is the fastest axis in the scan- ! line ordering, the one who's coordinates ! change the fastest as the elements are ! accessed in the order in which they ! appear in memory */ /* *************** *** 104,114 **** ** enough to be part of the basic nrrd type */ ! char *content; /* briefly, just what the hell is this data */ ! int blockSize; /* for nrrdTypeBlock array, block byte size */ ! double oldMin, oldMax; /* if non-NaN, and if nrrd is of integral ! type, extremal values for the array ! BEFORE it was quantized */ ! void *ptr; /* never read or set by nrrd; use/abuse ! as you see fit */ /* --- 107,117 ---- ** enough to be part of the basic nrrd type */ ! char *content; /* brief account of what this data is */ ! int blockSize; /* for nrrdTypeBlock:, block byte size */ ! double oldMin, oldMax; /* if non-NaN, and if nrrd is of integral ! type, extremal values for the array ! BEFORE it was quantized */ ! void *ptr; /* never read or set by nrrd; use/abuse ! as you see fit */ /* *************** *** 447,450 **** --- 450,454 ---- TEEM_API int nrrdStateGrayscaleImage3D; TEEM_API int nrrdStateKeyValueReturnInternalPointers; + TEEM_API int nrrdStateKindNoop; /* ---- BEGIN non-NrrdIO */ TEEM_API void nrrdDefGetenv(void); *************** *** 459,462 **** --- 463,467 ---- TEEM_API airEnum *nrrdEncodingType; TEEM_API airEnum *nrrdCenter; + TEEM_API airEnum *nrrdKind; TEEM_API airEnum *nrrdField; /* ---- BEGIN non-NrrdIO */ *************** *** 516,519 **** --- 521,525 ---- /******** axis info related */ /* axis.c */ + TEEM_API int nrrdKindSize(int kind); TEEM_API int nrrdAxisInfoCopy(Nrrd *nout, const Nrrd *nin, const int *axmap, int bitflag); *************** *** 524,537 **** TEEM_API void nrrdAxisInfoGet(const Nrrd *nrrd, int axInfo, ... /* void* */); ! TEEM_API double nrrdAxisPos(const Nrrd *nrrd, int ax, double idx); ! TEEM_API double nrrdAxisIdx(const Nrrd *nrrd, int ax, double pos); ! TEEM_API void nrrdAxisPosRange(double *loP, double *hiP, ! const Nrrd *nrrd, int ax, ! double loIdx, double hiIdx); ! TEEM_API void nrrdAxisIdxRange(double *loP, double *hiP, ! const Nrrd *nrrd, int ax, ! double loPos, double hiPos); ! TEEM_API void nrrdAxisSpacingSet(Nrrd *nrrd, int ax); ! TEEM_API void nrrdAxisMinMaxSet(Nrrd *nrrd, int ax, int defCenter); /******** simple things */ --- 530,543 ---- TEEM_API void nrrdAxisInfoGet(const Nrrd *nrrd, int axInfo, ... /* void* */); ! TEEM_API double nrrdAxisInfoPos(const Nrrd *nrrd, int ax, double idx); ! TEEM_API double nrrdAxisInfoIdx(const Nrrd *nrrd, int ax, double pos); ! TEEM_API void nrrdAxisInfoPosRange(double *loP, double *hiP, ! const Nrrd *nrrd, int ax, ! double loIdx, double hiIdx); ! TEEM_API void nrrdAxisInfoIdxRange(double *loP, double *hiP, ! const Nrrd *nrrd, int ax, ! double loPos, double hiPos); ! TEEM_API void nrrdAxisInfoSpacingSet(Nrrd *nrrd, int ax); ! TEEM_API void nrrdAxisInfoMinMaxSet(Nrrd *nrrd, int ax, int defCenter); /******** simple things */ Index: subset.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/subset.c,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** subset.c 7 Jan 2004 15:34:30 -0000 1.39 --- subset.c 30 Mar 2004 19:25:09 -0000 1.40 *************** *** 292,297 **** } for (d=0; d<nin->dim; d++) { ! nrrdAxisPosRange(&(nout->axis[d].min), &(nout->axis[d].max), ! nin, d, min[d], max[d]); } strcpy(buff1, ""); --- 292,298 ---- } for (d=0; d<nin->dim; d++) { ! nrrdAxisInfoPosRange(&(nout->axis[d].min), &(nout->axis[d].max), ! nin, d, min[d], max[d]); ! nout->axis[d].kind = _nrrdKindAltered(nin->axis[d].kind); } strcpy(buff1, ""); |