--- trunk/src/dnorm/dnorm.c 2010/06/29 15:13:36 125 +++ branches/vis12/src/dnorm/dnorm.c 2012/03/20 19:19:37 1739 @@ -33,8 +33,9 @@ "a consistent form, and nixes various other fields. "); int -main(int argc, char **argv) { - char *me, *outS; +main(int argc, const char **argv) { + const char *me; + char *outS; hestOpt *hopt; hestParm *hparm; airArray *mop; @@ -42,7 +43,7 @@ char *err; Nrrd *nin, *nout; NrrdIoState *nio; - int kindIn, kindOut, headerOnly; + int kindIn, kindOut, headerOnly, haveMM, trivialOrient; unsigned int kindAxis, axi, si, sj; me = argv[0]; @@ -52,6 +53,11 @@ airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hestOptAdd(&hopt, "h,header", NULL, airTypeInt, 0, 0, &headerOnly, NULL, "output header of nrrd file only, not the data itself"); + hestOptAdd(&hopt, "to", NULL, airTypeInt, 0, 0, &trivialOrient, NULL, + "(*t*rivial *o*rientation) " + "even if the input nrrd comes with full orientation or " + "per-axis min-max info, ignore it and instead assert the " + "most trivial mapping between index and world space"); hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL, "input image", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", @@ -71,22 +77,26 @@ /* make sure all kinds are set to something */ /* see if there's a range kind, verify that there's only one */ + /* set haveMM */ + haveMM = AIR_TRUE; kindIn = nrrdKindUnknown; kindAxis = 0; for (axi=0; axidim; axi++) { if (nrrdKindUnknown == nin->axis[axi].kind || nrrdKindIsDomain(nin->axis[axi].kind)) { - continue; - } - if (nrrdKindUnknown != kindIn) { - fprintf(stderr, "%s: got non-domain kind %s on axis %u, but already " - "have %s from axis %u\n", me, - airEnumStr(nrrdKind, nin->axis[axi].kind), axi, - airEnumStr(nrrdKind, kindIn), kindAxis); - airMopError(mop); exit(1); + haveMM &= AIR_EXISTS(nin->axis[axi].min); + haveMM &= AIR_EXISTS(nin->axis[axi].max); + } else { + if (nrrdKindUnknown != kindIn) { + fprintf(stderr, "%s: got non-domain kind %s on axis %u, but already " + "have %s from axis %u\n", me, + airEnumStr(nrrdKind, nin->axis[axi].kind), axi, + airEnumStr(nrrdKind, kindIn), kindAxis); + airMopError(mop); exit(1); + } + kindIn = nin->axis[axi].kind; + kindAxis = axi; } - kindIn = nin->axis[axi].kind; - kindAxis = axi; } /* see if the non-domain kind is something we can interpret as a tensor */ if (nrrdKindUnknown != kindIn) { @@ -120,14 +130,13 @@ kindOut = nrrdKindUnknown; } - /* prepare output (this may eventually be cropping or something else) */ + /* initialize output by copying */ nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdCopy(nout, nin)) { airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble copying:\n%s", me, err); airMopError(mop); exit(1); - } /* no comments, either advertising the format URL or anything else */ @@ -183,8 +192,10 @@ but we have to accept a greater variety of kinds and dimensions than gage ever has to process. */ - if (nout->spaceDim) { + if (nout->spaceDim && !trivialOrient) { int saxi = 0; + /* we use only the space dimension, not any named space */ + nout->space = nrrdSpaceUnknown; if (!nrrdSpaceVecExists(nout->spaceDim, nout->spaceOrigin)) { nrrdSpaceVecSetZero(nout->spaceOrigin); } @@ -200,6 +211,20 @@ nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection); } } + } else if (haveMM && !trivialOrient) { + int saxi = 0; + for (axi=0; axidim; axi++) { + if (nrrdKindUnknown == kindOut || kindAxis != axi) { + nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection); + nout->axis[axi].spaceDirection[saxi] + = (nin->axis[axi].max - nin->axis[axi].min)/(nin->axis[axi].size-1); + nout->spaceOrigin[saxi] = nin->axis[axi].min; + saxi++; + } else { + nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection); + } + } + nout->spaceDim = saxi; } else { int saxi = 0; nrrdSpaceVecSetZero(nout->spaceOrigin); @@ -217,7 +242,8 @@ } nout->spaceDim = saxi; } - /* probably should be asserted earlier */ + + /* space dimension has to match the number of domain axes */ if (nout->dim != nout->spaceDim + !!kindOut) { fprintf(stderr, "%s: output dim %d != spaceDim %d + %d %s%s%s\n", me, nout->dim, nout->spaceDim, !!kindOut,
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: output dim %d != spaceDim %d + %d %s%s%s\n", me, nout->dim, nout->spaceDim, !!kindOut,