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 2358, Sun Apr 7 15:17:59 2013 UTC revision 2359, Sun Apr 7 16:31:38 2013 UTC
# Line 43  Line 43 
43    char *err;    char *err;
44    Nrrd *nin, *nout;    Nrrd *nin, *nout;
45    NrrdIoState *nio;    NrrdIoState *nio;
46    int kindIn, kindOut, headerOnly, haveMM;    int kindIn, kindOut, headerOnly, haveMM, trivialOrient, recenter;
47    unsigned int kindAxis, axi, si, sj;    unsigned int kindAxis, axi, si, sj;
48      double sscl;
49    
50    me = argv[0];    me = argv[0];
51    mop = airMopNew();    mop = airMopNew();
# Line 53  Line 54 
54    airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);    airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);
55    hestOptAdd(&hopt, "h,header", NULL, airTypeInt, 0, 0, &headerOnly, NULL,    hestOptAdd(&hopt, "h,header", NULL, airTypeInt, 0, 0, &headerOnly, NULL,
56               "output header of nrrd file only, not the data itself");               "output header of nrrd file only, not the data itself");
57      hestOptAdd(&hopt, "to", NULL, airTypeInt, 0, 0, &trivialOrient, NULL,
58                 "(*t*rivial *o*rientation) "
59                 "even if the input nrrd comes with full orientation or "
60                 "per-axis min-max info, ignore it and instead assert the "
61                 "most trivial mapping between index and world space");
62      hestOptAdd(&hopt, "c", NULL, airTypeInt, 0, 0, &recenter, NULL,
63                 "re-locate output spaceOrigin so that field is centered "
64                 "around origin of space coordinates");
65      hestOptAdd(&hopt, "s", "scl", airTypeDouble, 1, 1, &sscl, "1.0",
66                 "when contriving orientation information, distance between "
67                 "samples to use");
68    hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL,    hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL,
69               "input image", NULL, NULL, nrrdHestNrrd);               "input image", NULL, NULL, nrrdHestNrrd);
70    hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",    hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",
# Line 187  Line 199 
199       but we have to accept a greater variety of kinds and dimensions       but we have to accept a greater variety of kinds and dimensions
200       than gage ever has to process.       than gage ever has to process.
201    */    */
202    if (nout->spaceDim) {    if (nout->spaceDim && !trivialOrient) {
203      int saxi = 0;      int saxi = 0;
204      /* we use only the space dimension, not any named space */      /* we use only the space dimension, not any named space */
205      nout->space = nrrdSpaceUnknown;      nout->space = nrrdSpaceUnknown;
# Line 199  Line 211 
211          if (!nrrdSpaceVecExists(nout->spaceDim,          if (!nrrdSpaceVecExists(nout->spaceDim,
212                                  nout->axis[axi].spaceDirection)) {                                  nout->axis[axi].spaceDirection)) {
213            nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection);            nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection);
214            nout->axis[axi].spaceDirection[saxi] = 1.0;            nout->axis[axi].spaceDirection[saxi] = sscl;
215          }          }
216          saxi++;          saxi++;
217        } else {        } else {
218          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
219        }        }
220      }      }
221    } else if (haveMM) {    } else if (haveMM && !trivialOrient) {
222      int saxi = 0;      int saxi = 0;
223      for (axi=0; axi<nout->dim; axi++) {      for (axi=0; axi<nout->dim; axi++) {
224        if (nrrdKindUnknown == kindOut || kindAxis != axi) {        if (nrrdKindUnknown == kindOut || kindAxis != axi) {
# Line 221  Line 233 
233      }      }
234      nout->spaceDim = saxi;      nout->spaceDim = saxi;
235    } else {    } else {
236        /* either trivialOrient, or not spaceDim, or not not haveMM */
237      int saxi = 0;      int saxi = 0;
238        nout->space = nrrdSpaceUnknown;
239      nrrdSpaceVecSetZero(nout->spaceOrigin);      nrrdSpaceVecSetZero(nout->spaceOrigin);
240      for (axi=0; axi<nout->dim; axi++) {      for (axi=0; axi<nout->dim; axi++) {
241        if (nrrdKindUnknown == kindOut || kindAxis != axi) {        if (nrrdKindUnknown == kindOut || kindAxis != axi) {
# Line 229  Line 243 
243          nout->axis[axi].spaceDirection[saxi]          nout->axis[axi].spaceDirection[saxi]
244            = (AIR_EXISTS(nin->axis[axi].spacing)            = (AIR_EXISTS(nin->axis[axi].spacing)
245               ? nin->axis[axi].spacing               ? nin->axis[axi].spacing
246               : 1.0);               : sscl);
247          saxi++;          saxi++;
248        } else {        } else {
249          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);          nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
# Line 248  Line 262 
262      airMopError(mop); exit(1);      airMopError(mop); exit(1);
263    }    }
264    
265      if (recenter) {
266        /* sets field's origin so field is centered on the origin. capiche? */
267        /* this code was tacked on later than the stuff above, so its
268           logic could probably be moved up there, but it seems cleaner to
269           have it as a separate post-process */
270        double mean[NRRD_SPACE_DIM_MAX];
271        nrrdSpaceVecSetZero(mean);
272        for (axi=0; axi<nout->dim; axi++) {
273          if (nrrdKindUnknown == kindOut || kindAxis != axi) {
274            nrrdSpaceVecScaleAdd2(mean, 1.0, mean,
275                                  0.5*(nout->axis[axi].size - 1),
276                                  nout->axis[axi].spaceDirection);
277          }
278        }
279        nrrdSpaceVecScaleAdd2(mean, 1.0, mean,
280                              1.0, nout->spaceOrigin);
281        /* now mean is the center of the field */
282        nrrdSpaceVecScaleAdd2(nout->spaceOrigin,
283                              1.0, nout->spaceOrigin,
284                              -1.0, mean);
285      }
286    
287    if (nrrdSave(outS, nout, nio)) {    if (nrrdSave(outS, nout, nio)) {
288      airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways);      airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways);
289      fprintf(stderr, "%s: trouble saving \"%s\":\n%s",      fprintf(stderr, "%s: trouble saving \"%s\":\n%s",

Legend:
Removed from v.2358  
changed lines
  Added in v.2359

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