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

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

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