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

SCM Repository

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

Diff of /trunk/src/dnorm/dnorm.c

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

revision 114, Wed Jun 23 19:39:36 2010 UTC revision 1235, Tue May 17 20:29:30 2011 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;    int kindIn, kindOut, headerOnly, haveMM;
47    unsigned int kindAxis, axi, si, sj;    unsigned int kindAxis, axi, si, sj;
48    
49    me = argv[0];    me = argv[0];
# Line 50  Line 51 
51    hparm = hestParmNew();    hparm = hestParmNew();
52    hopt = NULL;    hopt = NULL;
53    airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);    airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);
54      hestOptAdd(&hopt, "h,header", NULL, airTypeInt, 0, 0, &headerOnly, NULL,
55                 "output header of nrrd file only, not the data itself");
56    hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL,    hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL,
57               "input image", NULL, NULL, nrrdHestNrrd);               "input image", NULL, NULL, nrrdHestNrrd);
58    hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",    hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",
# Line 69  Line 72 
72    
73    /* make sure all kinds are set to something */    /* make sure all kinds are set to something */
74    /* 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 */
75      /* set haveMM */
76      haveMM = AIR_TRUE;
77    kindIn = nrrdKindUnknown;    kindIn = nrrdKindUnknown;
78    kindAxis = 0;    kindAxis = 0;
79    for (axi=0; axi<nin->dim; axi++) {    for (axi=0; axi<nin->dim; axi++) {
80      if (nrrdKindUnknown == nin->axis[axi].kind      if (nrrdKindUnknown == nin->axis[axi].kind
81          || nrrdKindIsDomain(nin->axis[axi].kind)) {          || nrrdKindIsDomain(nin->axis[axi].kind)) {
82        continue;        haveMM &= AIR_EXISTS(nin->axis[axi].min);
83      }        haveMM &= AIR_EXISTS(nin->axis[axi].max);
84        } else {
85      if (nrrdKindUnknown != kindIn) {      if (nrrdKindUnknown != kindIn) {
86        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 "
87                "have %s from axis %u\n", me,                "have %s from axis %u\n", me,
# Line 86  Line 92 
92      kindIn = nin->axis[axi].kind;      kindIn = nin->axis[axi].kind;
93      kindAxis = axi;      kindAxis = axi;
94    }    }
95      }
96    /* 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 */
97    if (nrrdKindUnknown != kindIn) {    if (nrrdKindUnknown != kindIn) {
98      switch (kindIn) {      switch (kindIn) {
# Line 118  Line 125 
125      kindOut = nrrdKindUnknown;      kindOut = nrrdKindUnknown;
126    }    }
127    
128    /* prepare output (this may eventually be cropping or something else) */    /* initialize output by copying */
129    nout = nrrdNew();    nout = nrrdNew();
130    airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);    airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
131    if (nrrdCopy(nout, nin)) {    if (nrrdCopy(nout, nin)) {
132      airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways);      airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways);
133      fprintf(stderr, "%s: trouble copying:\n%s", me, err);      fprintf(stderr, "%s: trouble copying:\n%s", me, err);
134      airMopError(mop); exit(1);      airMopError(mop); exit(1);
   
135    }    }
136    
137    /* no comments, either advertising the format URL or anything else */    /* no comments, either advertising the format URL or anything else */
138    nio = nrrdIoStateNew();    nio = nrrdIoStateNew();
139    airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways);    airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways);
140    nio->skipFormatURL = AIR_TRUE;    nio->skipFormatURL = AIR_TRUE;
141      if (headerOnly) {
142        nio->skipData = AIR_TRUE;
143      }
144    nrrdCommentClear(nout);    nrrdCommentClear(nout);
145    
146    /* no measurement frame */    /* no measurement frame */
# Line 180  Line 189 
189    */    */
190    if (nout->spaceDim) {    if (nout->spaceDim) {
191      int saxi = 0;      int saxi = 0;
192        /* we use only the space dimension, not any named space */
193        nout->space = nrrdSpaceUnknown;
194      if (!nrrdSpaceVecExists(nout->spaceDim, nout->spaceOrigin)) {      if (!nrrdSpaceVecExists(nout->spaceDim, nout->spaceOrigin)) {
195        nrrdSpaceVecSetZero(nout->spaceOrigin);        nrrdSpaceVecSetZero(nout->spaceOrigin);
196      }      }
# Line 195  Line 206 
206          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
207        }        }
208      }      }
209      } else if (haveMM) {
210        int saxi = 0;
211        for (axi=0; axi<nout->dim; axi++) {
212          if (nrrdKindUnknown == kindOut || kindAxis != axi) {
213            nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection);
214            nout->axis[axi].spaceDirection[saxi]
215              = (nin->axis[axi].max - nin->axis[axi].min)/(nin->axis[axi].size-1);
216            nout->spaceOrigin[saxi] = nin->axis[axi].min;
217            saxi++;
218          } else {
219            nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
220          }
221        }
222        nout->spaceDim = saxi;
223    } else {    } else {
224      int saxi = 0;      int saxi = 0;
225      nrrdSpaceVecSetZero(nout->spaceOrigin);      nrrdSpaceVecSetZero(nout->spaceOrigin);
226      for (axi=0; axi<nout->dim; axi++) {      for (axi=0; axi<nout->dim; axi++) {
227        if (nrrdKindUnknown == kindOut || kindAxis != axi) {        if (nrrdKindUnknown == kindOut || kindAxis != axi) {
228          nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection);          nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection);
229          nout->axis[axi].spaceDirection[saxi] = 1.0;          nout->axis[axi].spaceDirection[saxi]
230              = (AIR_EXISTS(nin->axis[axi].spacing)
231                 ? nin->axis[axi].spacing
232                 : 1.0);
233          saxi++;          saxi++;
234        } else {        } else {
235          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
# Line 209  Line 237 
237      }      }
238      nout->spaceDim = saxi;      nout->spaceDim = saxi;
239    }    }
240    /* probably should be asserted earlier */  
241      /* space dimension has to match the number of domain axes */
242    if (nout->dim != nout->spaceDim + !!kindOut) {    if (nout->dim != nout->spaceDim + !!kindOut) {
243      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",
244              me, nout->dim, nout->spaceDim, !!kindOut,              me, nout->dim, nout->spaceDim, !!kindOut,

Legend:
Removed from v.114  
changed lines
  Added in v.1235

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