Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/lamont/src/dnorm/dnorm.c
ViewVC logotype

Diff of /branches/lamont/src/dnorm/dnorm.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/dnorm/dnorm.c revision 125, Tue Jun 29 15:13:36 2010 UTC branches/vis12/src/dnorm/dnorm.c revision 1739, Tue Mar 20 19:19:37 2012 UTC
# Line 33  Line 33 
33                     "a consistent form, and nixes various other fields. ");                     "a consistent form, and nixes various other fields. ");
34    
35  int  int
36  main(int argc, char **argv) {  main(int argc, const char **argv) {
37    char *me, *outS;    const char *me;
38      char *outS;
39    hestOpt *hopt;    hestOpt *hopt;
40    hestParm *hparm;    hestParm *hparm;
41    airArray *mop;    airArray *mop;
# Line 42  Line 43 
43    char *err;    char *err;
44    Nrrd *nin, *nout;    Nrrd *nin, *nout;
45    NrrdIoState *nio;    NrrdIoState *nio;
46    int kindIn, kindOut, headerOnly;    int kindIn, kindOut, headerOnly, haveMM, trivialOrient;
47    unsigned int kindAxis, axi, si, sj;    unsigned int kindAxis, axi, si, sj;
48    
49    me = argv[0];    me = argv[0];
# Line 52  Line 53 
53    airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);    airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);
54    hestOptAdd(&hopt, "h,header", NULL, airTypeInt, 0, 0, &headerOnly, NULL,    hestOptAdd(&hopt, "h,header", NULL, airTypeInt, 0, 0, &headerOnly, NULL,
55               "output header of nrrd file only, not the data itself");               "output header of nrrd file only, not the data itself");
56      hestOptAdd(&hopt, "to", NULL, airTypeInt, 0, 0, &trivialOrient, NULL,
57                 "(*t*rivial *o*rientation) "
58                 "even if the input nrrd comes with full orientation or "
59                 "per-axis min-max info, ignore it and instead assert the "
60                 "most trivial mapping between index and world space");
61    hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL,    hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL,
62               "input image", NULL, NULL, nrrdHestNrrd);               "input image", NULL, NULL, nrrdHestNrrd);
63    hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",    hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",
# Line 71  Line 77 
77    
78    /* make sure all kinds are set to something */    /* make sure all kinds are set to something */
79    /* see if there's a range kind, verify that there's only one */    /* see if there's a range kind, verify that there's only one */
80      /* set haveMM */
81      haveMM = AIR_TRUE;
82    kindIn = nrrdKindUnknown;    kindIn = nrrdKindUnknown;
83    kindAxis = 0;    kindAxis = 0;
84    for (axi=0; axi<nin->dim; axi++) {    for (axi=0; axi<nin->dim; axi++) {
85      if (nrrdKindUnknown == nin->axis[axi].kind      if (nrrdKindUnknown == nin->axis[axi].kind
86          || nrrdKindIsDomain(nin->axis[axi].kind)) {          || nrrdKindIsDomain(nin->axis[axi].kind)) {
87        continue;        haveMM &= AIR_EXISTS(nin->axis[axi].min);
88      }        haveMM &= AIR_EXISTS(nin->axis[axi].max);
89        } else {
90      if (nrrdKindUnknown != kindIn) {      if (nrrdKindUnknown != kindIn) {
91        fprintf(stderr, "%s: got non-domain kind %s on axis %u, but already "        fprintf(stderr, "%s: got non-domain kind %s on axis %u, but already "
92                "have %s from axis %u\n", me,                "have %s from axis %u\n", me,
# Line 88  Line 97 
97      kindIn = nin->axis[axi].kind;      kindIn = nin->axis[axi].kind;
98      kindAxis = axi;      kindAxis = axi;
99    }    }
100      }
101    /* see if the non-domain kind is something we can interpret as a tensor */    /* see if the non-domain kind is something we can interpret as a tensor */
102    if (nrrdKindUnknown != kindIn) {    if (nrrdKindUnknown != kindIn) {
103      switch (kindIn) {      switch (kindIn) {
# Line 120  Line 130 
130      kindOut = nrrdKindUnknown;      kindOut = nrrdKindUnknown;
131    }    }
132    
133    /* prepare output (this may eventually be cropping or something else) */    /* initialize output by copying */
134    nout = nrrdNew();    nout = nrrdNew();
135    airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);    airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
136    if (nrrdCopy(nout, nin)) {    if (nrrdCopy(nout, nin)) {
137      airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways);      airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways);
138      fprintf(stderr, "%s: trouble copying:\n%s", me, err);      fprintf(stderr, "%s: trouble copying:\n%s", me, err);
139      airMopError(mop); exit(1);      airMopError(mop); exit(1);
   
140    }    }
141    
142    /* no comments, either advertising the format URL or anything else */    /* no comments, either advertising the format URL or anything else */
# Line 183  Line 192 
192       but we have to accept a greater variety of kinds and dimensions       but we have to accept a greater variety of kinds and dimensions
193       than gage ever has to process.       than gage ever has to process.
194    */    */
195    if (nout->spaceDim) {    if (nout->spaceDim && !trivialOrient) {
196      int saxi = 0;      int saxi = 0;
197        /* we use only the space dimension, not any named space */
198        nout->space = nrrdSpaceUnknown;
199      if (!nrrdSpaceVecExists(nout->spaceDim, nout->spaceOrigin)) {      if (!nrrdSpaceVecExists(nout->spaceDim, nout->spaceOrigin)) {
200        nrrdSpaceVecSetZero(nout->spaceOrigin);        nrrdSpaceVecSetZero(nout->spaceOrigin);
201      }      }
# Line 200  Line 211 
211          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
212        }        }
213      }      }
214      } else if (haveMM && !trivialOrient) {
215        int saxi = 0;
216        for (axi=0; axi<nout->dim; axi++) {
217          if (nrrdKindUnknown == kindOut || kindAxis != axi) {
218            nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection);
219            nout->axis[axi].spaceDirection[saxi]
220              = (nin->axis[axi].max - nin->axis[axi].min)/(nin->axis[axi].size-1);
221            nout->spaceOrigin[saxi] = nin->axis[axi].min;
222            saxi++;
223          } else {
224            nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
225          }
226        }
227        nout->spaceDim = saxi;
228    } else {    } else {
229      int saxi = 0;      int saxi = 0;
230      nrrdSpaceVecSetZero(nout->spaceOrigin);      nrrdSpaceVecSetZero(nout->spaceOrigin);
# Line 217  Line 242 
242      }      }
243      nout->spaceDim = saxi;      nout->spaceDim = saxi;
244    }    }
245    /* probably should be asserted earlier */  
246      /* space dimension has to match the number of domain axes */
247    if (nout->dim != nout->spaceDim + !!kindOut) {    if (nout->dim != nout->spaceDim + !!kindOut) {
248      fprintf(stderr, "%s: output dim %d != spaceDim %d + %d %s%s%s\n",      fprintf(stderr, "%s: output dim %d != spaceDim %d + %d %s%s%s\n",
249              me, nout->dim, nout->spaceDim, !!kindOut,              me, nout->dim, nout->spaceDim, !!kindOut,

Legend:
Removed from v.125  
changed lines
  Added in v.1739

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0