int
main(int argc, char *argv[]) {
  Nrrd *map, *ppm;
  NrrdRange *range;

  AIR_UNUSED(argc);
  me = argv[0];

  if (limnEnvMapFill(map=nrrdNew(), cb, limnQN16checker, NULL)) {
    fprintf(stderr, "%s: trouble:\n%s", me, biffGet(LIMN));
    exit(1);
  }
  range = nrrdRangeNew(0, 1);
  if (nrrdQuantize(ppm=nrrdNew(), map, range, 8)) {
    fprintf(stderr, "%s: trouble:\n%s", me, biffGet(NRRD));
    exit(1);
  }
  if (nrrdSave("map.ppm", ppm, NULL)) {
    fprintf(stderr, "%s: trouble:\n%s", me, biffGet(NRRD));
    exit(1);
  }

  nrrdNuke(map);
  nrrdNuke(ppm);
  nrrdRangeNix(range);
  exit(0);
}
Beispiel #2
0
int
main(int argc, char *argv[]) {
  Nrrd *hvol, *info;
  char *iStr, *dStr, *oStr;
  int dim;

  me = argv[0];
  if (argc != 4)
    usage();
  iStr = argv[1];
  dStr = argv[2];
  oStr = argv[3];

  if (nrrdLoad(hvol=nrrdNew(), iStr, NULL)) {
    fprintf(stderr, "%s: trouble reading hvol:\n%s\n", me, biffGet(NRRD));
    usage();
  }
  if (1 != sscanf(dStr, "%d", &dim)) {
    fprintf(stderr, "%s: trouble parsing %s as an int\n", me, dStr);
    usage();
  }
  if (baneOpacInfo(info = nrrdNew(), hvol, dim, nrrdMeasureHistoMean)) {
    fprintf(stderr, "%s: trouble calculting %d-D opacity info:\n%s\n",
            me, dim, biffGet(BANE));
    exit(1);
  }
  if (nrrdSave(oStr, info, NULL)) {
    fprintf(stderr, "%s: trouble saving nrrd to %s:\n%s\n", me, oStr,
            biffGet(NRRD));
    exit(1);
  }
  nrrdNuke(hvol);
  nrrdNuke(info);
  exit(0);
}
Beispiel #3
0
int
main(int argc, char *argv[]) {
  char *inS, *spcS, buff[512];
  dyeColor *col;
  int spc;
  
  me = argv[0];
  if (3 != argc)
    usage();
  inS = argv[1];
  spcS = argv[2];
  
  if (dyeColorParse(col = dyeColorNew(), inS)) {
    fprintf(stderr, "%s: trouble parsing \"%s\":\n%s", me, inS, biffGet(DYE));
    exit(1);
  }
  spc = dyeStrToSpace(spcS);
  if (dyeSpaceUnknown == spc) {
    fprintf(stderr, "%s: couldn't parse \"%s\" as colorspace\n", me, spcS);
    exit(1);
  }
  if (dyeConvert(col, spc)) {
    fprintf(stderr, "%s: trouble converting to %s:\n%s", 
            me, spcS, biffGet(DYE));
    exit(1);
  }
  printf("%s\n", dyeColorSprintf(buff, col));

  col = dyeColorNix(col);
  exit(0);
}
Beispiel #4
0
int
main(int argc, char **argv) {
  char *me, *err;
  Nrrd *nrrd;
  NrrdIoState *nio;
  char hstr[] = "NRRD0001\n"
    "# Complete NRRD file format specification at:\n"
    "# http://teem.sourceforge.net/nrrd/format.html\n"
    "# one comment\n"
    "# two comment\n"
    "# three comment\n"
    "type: float\n"
    "dimension: 2\n"
    "sizes: 91 114\n"
    "centerings: node node\n"
    "endian: big\n"
    "encoding: raw\n"
    "bingo:=bob\n"
    "foo:=super duper fancy bar with corona\n"
    /* "data file: tmp.raw\n" */;
  char *wstr;
  AIR_UNUSED(argc);
  me = argv[0];

  nrrdStateVerboseIO = 10;

  nio = nrrdIoStateNew();
  nrrd = nrrdNew();

  nio->path = airStrdup(".");
  if (nrrdStringRead(nrrd, hstr, nio)) {
    fprintf(stderr, "%s: trouble reading string:\n%s", 
            me, err = biffGet(NRRD));
    free(err);
    exit(1);
  }
  fprintf(stderr, "%s: nrrd->data = %p\n", me, nrrd->data);

  nrrdSave("out.nrrd", nrrd, NULL);
  if (nrrdStringWrite(&wstr, nrrd, NULL)) {
    fprintf(stderr, "%s: trouble writing string:\n%s", 
            me, err = biffGet(NRRD));
    free(err);
    exit(1);
  }
  fprintf(stderr, "%s: |%s|\n", me, wstr);

  free(wstr);
  nrrdIoStateNix(nio);
  nrrdNuke(nrrd);

  exit(0);
}
Beispiel #5
0
int
main(int argc, char *argv[]) {
  char *me, *fileS;
  FILE *file;
  unsigned int llen;
  NrrdIoState *io;

  me = argv[0];
  if (2 != argc) {
    /*                       0   1   (2) */
    fprintf(stderr, "usage: %s <file>\n", me);
    exit(1);
  }
  fileS = argv[1];
  if (!( file = myopen(fileS) )) {
    fprintf(stderr, "%s: couldn't open \"%s\" for reading\n", me, fileS);
    exit(1);
  }
  io = nrrdIoStateNew();
  do {
    if (_nrrdOneLine(&llen, io, file)) {
      fprintf(stderr, "%s: trouble:\n%s", me, biffGet(NRRD));
      exit(1);
    }
    if (llen) {
      printf("%2u   |%s|\n", llen, io->line);
    }
  } while(llen > 0);
  nrrdIoStateNix(io);
  myclose(file);

  exit(0);
}
int
main(int argc, char **argv) {
  char *err;

  fprintf(stderr, "(from Teem %s, %s)\n", 
          airTeemVersion, airTeemReleaseDate);

  if (!nrrdSanity()) {
    fprintf(stderr, "\n");
    fprintf(stderr, "!!! nrrd sanity check FAILED: fix and re-compile\n");
    err = biffGet(NRRD);
    fprintf(stderr, "%s\n", err);
    free(err); 
    return 1;
  } else {
    fprintf(stderr, "(nrrdSanity check passed)\n\n");
  }

  if (2 != argc) {
    fprintf(stderr, "usage: demoIO <filename>\n");
    return 1;
  }

  demoIO(argv[1]);

  return 0;
}
Beispiel #7
0
int
main(int argc, char **argv) {
  char *me, *err;
  Nrrd *nrrd;
  NrrdRange *range;

  me = argv[0];
  if (2 != argc)
    usage(me);

  nrrdStateVerboseIO = 10;
  
  if (nrrdLoad(nrrd=nrrdNew(), argv[1], NULL)) {
    fprintf(stderr, "%s: trouble loading \"%s\":\n%s", 
            me, argv[1], err = biffGet(NRRD));
    free(err);
    exit(1);
  }

  range = nrrdRangeNewSet(nrrd, nrrdBlind8BitRangeState);

  printf("%s: min = %g; max = %g, hasNonExist = %d\n", me,
         range->min, range->max, range->hasNonExist);

  nrrdNuke(nrrd);

  exit(0);
}
int
main(int argc, char *argv[]) {
  Nrrd *info;
  float sigma;

  AIR_UNUSED(argc);
  if (nrrdLoad(info=nrrdNew(), argv[1], NULL)) {
    fprintf(stderr, "trouble:\n%s\n", biffGet(BANE));
  }
  if (baneSigmaCalc(&sigma, info)) {
    fprintf(stderr, "trouble:\n%s\n", biffGet(BANE));
  }
  printf("%g\n", sigma);

  nrrdNuke(info);
  return 0;
}
Beispiel #9
0
char *
biffGetDone(const char *key) {
  char *ret;

  _bmsgStart();

  ret = biffGet(key);
  biffDone(key);  /* will call _bmsgFinish if this is the last key */

  return ret;
}
Beispiel #10
0
int
main(int argc, char *argv[]) {
  Nrrd *info, *pos;
  float sigma, gthresh;
  char *iStr, *oStr, *sigStr, *gthStr;

  me = argv[0];
  if (argc != 5) {
    usage();
  }
  iStr = argv[1];
  sigStr = argv[2];
  gthStr = argv[3];
  oStr = argv[4];

  if (1 != sscanf(sigStr, "%g", &sigma) ||
      1 != sscanf(gthStr, "%g", &gthresh)) {
    fprintf(stderr, "%s: couldn't parse %s and %s as floats\n", me, 
            sigStr, gthStr);
    usage();
  }

  if (nrrdLoad(info=nrrdNew(), iStr, NULL)) {
    fprintf(stderr, "%s: trouble reading \"%s\" :\n%s\n", me, 
            iStr, biffGet(NRRD));
    exit(1);
  }
  if (banePosCalc(pos = nrrdNew(), sigma, gthresh, info)) {
    fprintf(stderr, "%s: trouble calculating %s:\n%s\n", me,
            2 == info->dim ? "p(v,g)" : "p(v)", biffGet(BANE));
    exit(1);
  }
  if (nrrdSave(oStr, pos, NULL)) {
    fprintf(stderr, "%s: trouble writing output to \"%s\"\n", me, oStr);
    exit(1);
  }
  nrrdNuke(info);
  nrrdNuke(pos);
  exit(0);
}
Beispiel #11
0
float *
_baneTRexRead(char *fname) {
  char me[]="_baneTRexRead";

  if (nrrdLoad(baneNpos=nrrdNew(), fname, NULL)) {
    fprintf(stderr, "%s: !!! trouble reading \"%s\":\n%s\n", me, 
            fname, biffGet(NRRD));
    return NULL;
  }
  if (banePosCheck(baneNpos, 1)) {
    fprintf(stderr, "%s: !!! didn't get a valid p(x) file:\n%s\n", me, 
            biffGet(BANE));
    return NULL;
  }
  if (TREX_LUTLEN != baneNpos->axis[0].size) {
    fprintf(stderr, "%s: !!! need a length %d p(x) (not " _AIR_SIZE_T_CNV
            ")\n", me, TREX_LUTLEN, baneNpos->axis[0].size); 
    return NULL;
  }

  return (float *)baneNpos->data;
}
char *
biffGetDone(const char *key) {
  char *ret;

  _biffInit();
  _biffCheckKey(key);

  ret = biffGet(key);
  biffDone(key);
  _biffNuke();

  return ret;
}
Beispiel #13
0
int
main(int argc, const char *argv[]) {
  const char *me;
  char *err;
  limnCamera *cam;
  float mat[16];
  hestOpt *hopt=NULL;
  airArray *mop;

  mop = airMopNew();
  cam = limnCameraNew();
  airMopAdd(mop, cam, (airMopper)limnCameraNix, airMopAlways);

  me = argv[0];
  hestOptAdd(&hopt, "fr", "eye pos", airTypeDouble, 3, 3, cam->from,
             NULL, "camera eye point");
  hestOptAdd(&hopt, "at", "at pos", airTypeDouble, 3, 3, cam->at,
             "0 0 0", "camera look-at point");
  hestOptAdd(&hopt, "up", "up dir", airTypeDouble, 3, 3, cam->up,
             "0 0 1", "camera pseudo up vector");
  hestOptAdd(&hopt, "rh", NULL, airTypeInt, 0, 0, &(cam->rightHanded), NULL,
             "use a right-handed UVN frame (V points down)");
  hestParseOrDie(hopt, argc-1, argv+1, NULL,
                 me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  cam->neer = -1;
  cam->dist = 0;
  cam->faar = 1;
  cam->atRelative = AIR_TRUE;

  if (limnCameraUpdate(cam)) {
    fprintf(stderr, "%s: trouble:\n%s\n", me, err = biffGet(LIMN));
    free(err);
    return 1;
  }

  printf("%s: W2V:\n", me);
  ELL_4M_COPY(mat, cam->W2V);
  ell_4m_print_f(stdout, mat);

  printf("\n");
  printf("%s: V2W:\n", me);
  ELL_4M_COPY(mat, cam->V2W);
  ell_4m_print_f(stdout, mat);

  airMopOkay(mop);
  return 0;
}
Beispiel #14
0
int
main(int argc, char *argv[]) {
  char *bStr, *pStr, *oStr;
  Nrrd *b, *p, *o;

  me = argv[0];
  if (argc != 4) 
    usage();
  bStr = argv[1];
  pStr = argv[2];
  oStr = argv[3];
  if (nrrdLoad(b=nrrdNew(), bStr, NULL)) {
    fprintf(stderr, "%s: trouble reading %s:\n%s\n", me, bStr, biffGet(NRRD));
    usage();
  }

  if (nrrdLoad(p=nrrdNew(), pStr, NULL)) {
    fprintf(stderr, "%s: trouble reading %s:\n%s\n", me, pStr, biffGet(NRRD));
    usage();
  }
  
  if (baneOpacCalc(o = nrrdNew(), b, p)) {
    fprintf(stderr, "%s: trouble calculating opac:\n%s", me, biffGet(BANE));
    exit(1);
  }

  if (nrrdSave(oStr, o, NULL)) {
    fprintf(stderr, "%s: trouble writing %s:\n%s\n", me, oStr, biffGet(NRRD));
    exit(1);
  }

  nrrdNuke(o);
  nrrdNuke(b);
  nrrdNuke(p);
  exit(0);
}
Beispiel #15
0
int
main() {
  char *tmp;

  /*
  biffAdd("axis", "the first error axis");
  biffAdd("axis", "the second error axis");
  biffAdd("axis", "the third error axis");
  biffAdd("chard", "the first error chard");
  biffAdd("chard", "the second error chard");
  biffAdd("chard", "the third error chard");
  biffAdd("bingo", "zero-eth bingo message");
  biffMove("bingo", NULL, "chard");
  biffAdd("bingo", "the first error bingo");
  biffAdd("bingo", "the second bll boo boo boo error bingo");
  biffAdd("bingo", "the third error bingo");
  printf("%s\n", (tmp = biffGet("bingo")));
  free(tmp);
  biffDone("bingo");
  printf("%s\n", (tmp = biffGet("chard")));
  free(tmp);
  biffDone("chard");
  printf("%s\n", (tmp = biffGet("axis")));
  free(tmp);
  biffDone("axis");
  
  biffAdd("harold", "the first error harold");
  biffAdd("harold", "the second error harold");
  biffAdd("harold", "the third error harold");
  printf("%s\n", (tmp = biffGet("harold")));
  free(tmp);
  */
  biffAdd("axis", "the first error axis");
  biffAdd("axis", "the second error axis");
  biffAdd("axis", "the third error axis");
  biffAdd("axis", "the fourth error axis");
  biffAdd("axis", "the fifth error axis");
  printf("%s\n", (tmp = biffGet("axis")));
  free(tmp);
  biffDone("axis");

  exit(0);
}
Beispiel #16
0
int
main(int argc, const char *argv[]) {
  const char *me;
  char *err, *inS, *outS;
  limnCamera *cam;
  float bg[3], winscale, edgeWidth[5], creaseAngle;
  hestOpt *hopt=NULL;
  airArray *mop;
  limnObject *obj;
  limnLook *look; unsigned int lookIdx;
  limnWindow *win;
  Nrrd *nmap;
  FILE *file;
  int wire, concave, describe, reverse, nobg;

  mop = airMopNew();
  cam = limnCameraNew();
  airMopAdd(mop, cam, (airMopper)limnCameraNix, airMopAlways);

  me = argv[0];
  hestOptAdd(&hopt, "i", "input OFF", airTypeString, 1, 1, &inS, NULL,
             "input OFF file");
  hestOptAdd(&hopt, "fr", "from point", airTypeDouble, 3, 3, cam->from,"4 4 4",
             "position of camera, used to determine view vector");
  hestOptAdd(&hopt, "at", "at point", airTypeDouble, 3, 3, cam->at, "0 0 0",
             "camera look-at point, used to determine view vector");
  hestOptAdd(&hopt, "up", "up vector", airTypeDouble, 3, 3, cam->up, "0 0 1",
             "camera pseudo-up vector, used to determine view coordinates");
  hestOptAdd(&hopt, "rh", NULL, airTypeInt, 0, 0, &(cam->rightHanded), NULL,
             "use a right-handed UVN frame (V points down)");
  hestOptAdd(&hopt, "or", NULL, airTypeInt, 0, 0, &(cam->orthographic), NULL,
             "use orthogonal projection");
  hestOptAdd(&hopt, "ur", "uMin uMax", airTypeDouble, 2, 2, cam->uRange,
             "-1 1", "range in U direction of image plane");
  hestOptAdd(&hopt, "vr", "vMin vMax", airTypeDouble, 2, 2, cam->vRange,
             "-1 1", "range in V direction of image plane");
  hestOptAdd(&hopt, "e", "envmap", airTypeOther, 1, 1, &nmap, "",
             "16octa-based environment map",
             NULL, NULL, nrrdHestNrrd);
  hestOptAdd(&hopt, "ws", "winscale", airTypeFloat, 1, 1, &winscale,
             "200", "world to points (PostScript) scaling");
  hestOptAdd(&hopt, "wire", NULL, airTypeInt, 0, 0, &wire, NULL,
             "just do wire-frame rendering");
  hestOptAdd(&hopt, "concave", NULL, airTypeInt, 0, 0, &concave, NULL,
             "use slightly buggy rendering method suitable for "
             "concave or self-occluding objects");
  hestOptAdd(&hopt, "reverse", NULL, airTypeInt, 0, 0, &reverse, NULL,
             "reverse ordering of vertices per face (needed if they "
             "specified in clockwise order)");
  hestOptAdd(&hopt, "describe", NULL, airTypeInt, 0, 0, &describe, NULL,
             "for debugging: list object definition of OFF read");
  hestOptAdd(&hopt, "bg", "background", airTypeFloat, 3, 3, bg, "1 1 1",
             "background RGB color; each component in range [0.0,1.0]");
  hestOptAdd(&hopt, "nobg", NULL, airTypeInt, 0, 0, &nobg, NULL,
             "don't initially fill with background color");
  hestOptAdd(&hopt, "wd", "5 widths", airTypeFloat, 5, 5, edgeWidth,
             "0.0 0.0 3.0 2.0 0.0",
             "width of edges drawn for five kinds of "
             "edges: back non-crease, back crease, "
             "silohuette, front crease, front non-crease");
  hestOptAdd(&hopt, "ca", "angle", airTypeFloat, 1, 1, &creaseAngle, "30",
             "dihedral angles greater than this are creases");
  hestOptAdd(&hopt, "o", "output PS", airTypeString, 1, 1, &outS, "out.ps",
             "output file to render postscript into");
  hestParseOrDie(hopt, argc-1, argv+1, NULL,
                 me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  cam->neer = -0.000000001;
  cam->dist = 0;
  cam->faar = 0.0000000001;
  cam->atRelative = AIR_TRUE;

  if (limnCameraUpdate(cam)) {
    fprintf(stderr, "%s: trouble:\n%s\n", me, err = biffGet(LIMN));
    free(err);
    return 1;
  }

  obj = limnObjectNew(10, AIR_TRUE);
  airMopAdd(mop, obj, (airMopper)limnObjectNix, airMopAlways);
  if (!(file = airFopen(inS, stdin, "r"))) {
    fprintf(stderr, "%s: couldn't open \"%s\" for reading\n", me, inS);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);
  if (limnObjectReadOFF(obj, file)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:\n%s\n", me, err);
    airMopError(mop); return 1;
  }
  if (describe) {
    fprintf(stdout, "----------------- POST-READ -----------------\n");
    limnObjectDescribe(stdout, obj);
    fprintf(stdout, "----------------- POST-READ -----------------\n");
  }
  if (reverse) {
    if (limnObjectFaceReverse(obj)) {
      airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
      fprintf(stderr, "%s: trouble:\n%s\n", me, err);
      airMopError(mop); return 1;
    }
  }
  if (describe) {
    fprintf(stdout, "----------------- POST-REVERSE -----------------\n");
    limnObjectDescribe(stdout, obj);
    fprintf(stdout, "----------------- POST-REVERSE -----------------\n");
  }
  win = limnWindowNew(limnDevicePS);
  win->ps.lineWidth[limnEdgeTypeBackFacet] = edgeWidth[0];
  win->ps.lineWidth[limnEdgeTypeBackCrease] = edgeWidth[1];
  win->ps.lineWidth[limnEdgeTypeContour] = edgeWidth[2];
  win->ps.lineWidth[limnEdgeTypeFrontCrease] = edgeWidth[3];
  win->ps.lineWidth[limnEdgeTypeFrontFacet] = edgeWidth[4];

  win->ps.wireFrame = wire;
  win->ps.creaseAngle = creaseAngle;
  win->ps.noBackground = nobg;
  ELL_3V_COPY(win->ps.bg, bg);

  win->file = airFopen(outS, stdout, "w");
  airMopAdd(mop, win, (airMopper)limnWindowNix, airMopAlways);
  win->scale = winscale;

  for (lookIdx=0; lookIdx<obj->lookNum; lookIdx++) {
    look = obj->look + lookIdx;
    /* earlier version of limn/test/soid used (0.2,0.8,0.0), I think.
       Now we assume that any useful shading is happening in the emap */
    ELL_3V_SET(look->kads, 0.2, 0.8, 0);
  }

  if (limnObjectRender(obj, cam, win)
      || (concave
          ? limnObjectPSDrawConcave(obj, cam, nmap, win)
          : limnObjectPSDraw(obj, cam, nmap, win))) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:\n%s\n", me, err);
    airMopError(mop); return 1;
  }
  fclose(win->file);

  if (describe) {
    fprintf(stdout, "----------------- POST-RENDER -----------------\n");
    limnObjectDescribe(stdout, obj);
    fprintf(stdout, "----------------- POST-RENDER -----------------\n");
  }

  airMopOkay(mop);
  return 0;
}
Beispiel #17
0
int
unrrdu_dnormMain(int argc, const char **argv, const char *me,
                 hestParm *hparm) {
    char *outS;
    int pret;

    Nrrd *nin, *nout;
    NrrdIoState *nio;
    int kindIn, kindOut, headerOnly, haveMM, trivialOrient, recenter, gotmf;
    unsigned int kindAxis, axi, si, sj;
    double sscl;

    hestOpt *opt = NULL;
    char *err;
    airArray *mop;

    hestOptAdd(&opt, "h,header", NULL, airTypeInt, 0, 0, &headerOnly, NULL,
               "output header of nrrd file only, not the data itself");
    hestOptAdd(&opt, "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 "
               "identity mapping between index and world space");
    hestOptAdd(&opt, "c,center", NULL, airTypeInt, 0, 0, &recenter, NULL,
               "re-locate output spaceOrigin so that field is centered "
               "around origin of space coordinates");
    hestOptAdd(&opt, "s,scaling", "scl", airTypeDouble, 1, 1, &sscl, "1.0",
               "when having to contrive orientation information and there's "
               "no per-axis min/max to inform what the sample spacing is, "
               "this is the sample spacing to assert");
    OPT_ADD_NIN(nin, "input image");
    OPT_ADD_NOUT(outS, "output filename");

    mop = airMopNew();
    airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
    USAGE(_unrrdu_dnormInfoL);
    PARSE();
    airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);

    /* can't deal with block type */
    if (nrrdTypeBlock == nin->type) {
        fprintf(stderr, "%s: can only have scalar kinds (not %s)\n", me,
                airEnumStr(nrrdType, nrrdTypeBlock));
        airMopError(mop);
        exit(1);
    }

    /* 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; axi<nin->dim; axi++) {
        if (nrrdKindUnknown == nin->axis[axi].kind
                || nrrdKindIsDomain(nin->axis[axi].kind)) {
            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;
        }
    }
    /* see if the non-domain kind is something we can interpret as a tensor */
    if (nrrdKindUnknown != kindIn) {
        switch (kindIn) {
        /* ======= THESE are the kinds that we can possibly output ======= */
        case nrrdKind2Vector:
        case nrrdKind3Vector:
        case nrrdKind4Vector:
        case nrrdKind2DSymMatrix:
        case nrrdKind2DMatrix:
        case nrrdKind3DSymMatrix:
        case nrrdKind3DMatrix:
            /* =============================================================== */
            kindOut = kindIn;
            break;
        /* Some other kinds are mapped to those above */
        case nrrdKind3Color:
        case nrrdKindRGBColor:
            kindOut = nrrdKind3Vector;
            break;
        case nrrdKind4Color:
        case nrrdKindRGBAColor:
            kindOut = nrrdKind4Vector;
            break;
        default:
            fprintf(stderr, "%s: got non-conforming kind %s on axis %u\n", me,
                    airEnumStr(nrrdKind, kindIn), kindAxis);
            airMopError(mop);
            exit(1);
            break;
        }
    } else {
        /* kindIn is nrrdKindUnknown, so its a simple scalar image,
           and that's what the output will be too; kindOut == nrrdKindUnknown
           is used in the code below to say "its a scalar image" */
        kindOut = nrrdKindUnknown;
    }

    /* 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 */
    nio = nrrdIoStateNew();
    airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways);
    nio->skipFormatURL = AIR_TRUE;
    if (headerOnly) {
        nio->skipData = AIR_TRUE;
    }
    nrrdCommentClear(nout);

    /* no measurement frame */
    gotmf = AIR_FALSE;
    for (si=0; si<NRRD_SPACE_DIM_MAX; si++) {
        for (sj=0; sj<NRRD_SPACE_DIM_MAX; sj++) {
            gotmf |= AIR_EXISTS(nout->measurementFrame[si][sj]);
        }
    }
    if (gotmf) {
        fprintf(stderr, "%s: WARNING: incoming array measurement frame; "
                "it will be erased on output.\n", me);
        /* airMopError(mop); exit(1); */
    }
    for (si=0; si<NRRD_SPACE_DIM_MAX; si++) {
        for (sj=0; sj<NRRD_SPACE_DIM_MAX; sj++) {
            nout->measurementFrame[si][sj] = AIR_NAN;
        }
    }

    /* no key/value pairs */
    nrrdKeyValueClear(nout);

    /* no content field */
    nout->content = airFree(nout->content);

    /* normalize domain kinds to "space" */
    /* turn off centers (Diderot assumes cell-centered, but that could
       probably stand to be tested and enforced more) */
    /* turn off thickness */
    /* turn off labels and units */
    for (axi=0; axi<nout->dim; axi++) {
        if (nrrdKindUnknown == kindOut) {
            nout->axis[axi].kind = nrrdKindSpace;
        } else {
            nout->axis[axi].kind = (kindAxis == axi
                                    ? kindOut
                                    : nrrdKindSpace);
        }
        nout->axis[axi].center = nrrdCenterUnknown;
        nout->axis[axi].thickness = AIR_NAN;
        nout->axis[axi].label = airFree(nout->axis[axi].label);
        nout->axis[axi].units = airFree(nout->axis[axi].units);
        nout->axis[axi].min = AIR_NAN;
        nout->axis[axi].max = AIR_NAN;
        nout->axis[axi].spacing = AIR_NAN;
    }

    /* logic of orientation definition:
       If space dimension is known:
          set origin to zero if not already set
          set space direction to unit vector if not already set
       Else if have per-axis min and max:
          set spae origin and directions to communicate same intent
          as original per-axis min and max and original centering
       Else
          set origin to zero and all space directions to units.
       It might be nice to use gage's logic for mapping from world to index,
       but we have to accept a greater variety of kinds and dimensions
       than gage ever has to process.
    */
    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);
        }
        for (axi=0; axi<nout->dim; axi++) {
            if (nrrdKindUnknown == kindOut || kindAxis != axi) {
                /* its a domain axis of output */
                if (!nrrdSpaceVecExists(nout->spaceDim,
                                        nout->axis[axi].spaceDirection)) {
                    nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection);
                    nout->axis[axi].spaceDirection[saxi] = sscl;
                }
                /* else we leave existing space vector as is */
                saxi++;
            } else {
                /* else its a range axis */
                nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
            }
        }
    } else if (haveMM && !trivialOrient) {
        int saxi = 0;
        size_t N;
        double rng;
        for (axi=0; axi<nout->dim; axi++) {
            if (nrrdKindUnknown == kindOut || kindAxis != axi) {
                /* its a domain axis of output */
                nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection);
                rng = nin->axis[axi].max - nin->axis[axi].min;
                if (nrrdCenterNode == nin->axis[axi].center) {
                    nout->spaceOrigin[saxi] = nin->axis[axi].min;
                    N = nin->axis[axi].size;
                    nout->axis[axi].spaceDirection[saxi] = rng/(N-1);
                } else {
                    /* unknown centering treated as cell */
                    N = nin->axis[axi].size;
                    nout->spaceOrigin[saxi] = nin->axis[axi].min + (rng/N)/2;
                    nout->axis[axi].spaceDirection[saxi] = rng/N;
                }
                saxi++;
            } else {
                /* else its a range axis */
                nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
            }
        }
        nout->spaceDim = saxi;
    } else {
        /* either trivialOrient, or, not spaceDim and not haveMM */
        int saxi = 0;
        nout->space = nrrdSpaceUnknown;
        nrrdSpaceVecSetZero(nout->spaceOrigin);
        for (axi=0; axi<nout->dim; axi++) {
            if (nrrdKindUnknown == kindOut || kindAxis != axi) {
                /* its a domain axis of output */
                nrrdSpaceVecSetZero(nout->axis[axi].spaceDirection);
                nout->axis[axi].spaceDirection[saxi]
                    = (AIR_EXISTS(nin->axis[axi].spacing)
                       ? nin->axis[axi].spacing
                       : sscl);
                saxi++;
            } else {
                /* else its a range axis */
                nrrdSpaceVecSetNaN(nout->axis[axi].spaceDirection);
            }
        }
        nout->spaceDim = saxi;
    }

    /* 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,
                kindOut ? "for non-scalar (" : "(scalar data)",
                kindOut ? airEnumStr(nrrdKind, kindOut) : "",
                kindOut ? ") data" : "");
        airMopError(mop);
        exit(1);
    }

    if (recenter) {
        /* sets field's origin so field is centered on the origin. capiche? */
        /* this code was tacked on later than the stuff above, so its
           logic could probably be moved up there, but it seems cleaner to
           have it as a separate post-process */
        double mean[NRRD_SPACE_DIM_MAX];
        nrrdSpaceVecSetZero(mean);
        for (axi=0; axi<nout->dim; axi++) {
            if (nrrdKindUnknown == kindOut || kindAxis != axi) {
                nrrdSpaceVecScaleAdd2(mean, 1.0, mean,
                                      0.5*(nout->axis[axi].size - 1),
                                      nout->axis[axi].spaceDirection);
            }
        }
        nrrdSpaceVecScaleAdd2(mean, 1.0, mean,
                              1.0, nout->spaceOrigin);
        /* now mean is the center of the field */
        nrrdSpaceVecScaleAdd2(nout->spaceOrigin,
                              1.0, nout->spaceOrigin,
                              -1.0, mean);
    }

    if (nrrdSave(outS, nout, nio)) {
        airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways);
        fprintf(stderr, "%s: trouble saving \"%s\":\n%s",
                me, outS, err);
        airMopError(mop);
        exit(1);
    }

    airMopOkay(mop);
    return 0;
}
Beispiel #18
0
int
main(int argc, const char *argv[]) {
    const char *me;
    char *tmp;
    airArray *mop;

    AIR_UNUSED(argc);
    me = argv[0];
    mop = airMopNew();

    /* HEY: the creation and comparison of these strings is not very
       flexible, especially the hard-coded "good[]" strings */
    biffAdd("axis", "the first error axis");
    biffAdd("chard", "the first error chard");
    biffAdd("chard", "the second error chard");
    biffAdd("axis", "the second error axis");
    biffAdd("chard", "the third error chard");
    biffAdd("bingo", "zero-eth bingo message");
    biffMove("bingo", NULL, "chard");
    biffAdd("bingo", "the first error bingo");
    biffAdd("bingo", "the second bll boo boo boo error bingo");
    biffAdd("bingo", "the third error bingo");
    biffAdd("axis", "the third error axis");
    {
        char good[] = ("[bingo] the third error bingo\n"
                       "[bingo] the second bll boo boo boo error bingo\n"
                       "[bingo] the first error bingo\n"
                       "[bingo] [chard] the third error chard\n"
                       "[bingo] [chard] the second error chard\n"
                       "[bingo] [chard] the first error chard\n"
                       "[bingo] zero-eth bingo message\n");
        tmp = biffGet("bingo");
        airMopAdd(mop, tmp, airFree, airMopAlways);

        /* an ugly macro */
#define COMPARE(N)                                                 \
    airMopAdd(mop, tmp, airFree, airMopAlways);                    \
    if (strcmp(tmp, good)) {                                       \
      fprintf(stderr, "%s: %d: #%s# != #%s#\n", me, N, tmp, good); \
      airMopError(mop);                                            \
      exit(1);                                                     \
    }

        COMPARE(1);
    }

    {
        char good[] = "";
        tmp = biffGet("chard");
        COMPARE(2);
    }

    {
        char good[] = ("[axis] the third error axis\n"
                       "[axis] the second error axis\n"
                       "[axis] the first error axis\n");
        tmp = biffGet("axis");
        COMPARE(3);
    }

    biffAdd("harold", "the first error harold");
    biffAdd("harold", "the second error harold");
    biffAdd("harold", "the third error harold");
    {
        char good[] = ("[harold] the third error harold\n"
                       "[harold] the second error harold\n"
                       "[harold] the first error harold\n");
        tmp = biffGetDone("harold");
        COMPARE(4);
    }

    biffDone("bingo");
    biffDone("axis");
    biffDone("chard");

    biffAdd("axis", "the first error axis");
    biffAdd("axis", "the second error axis");
    biffAdd("axis", "the third error axis");
    biffAdd("axis", "the fourth error axis");
    biffAdd("axis", "the fifth error axis");
    {
        char good[] = ("[axis] the fifth error axis\n"
                       "[axis] the fourth error axis\n"
                       "[axis] the third error axis\n"
                       "[axis] the second error axis\n"
                       "[axis] the first error axis\n");
        tmp = biffGetDone("axis");
        COMPARE(5);
    }

    biffAddf("test", "%s: this is a test of biffAddf %d %g", "me", 1, 4.2);
    {
        char good[] = "[test] me: this is a test of biffAddf 1 4.2\n";
        tmp = biffGetDone("test");
        COMPARE(6);
    }

    biffAddf("test2", "%s: this is a test of biffAddf %d %g", "me", 1, 4.2);
    biffMovef("test3", "test2", "%s: testing biffMove %d.", "me", 1729);
    {
        char good[] = ("[test3] me: testing biffMove 1729.\n"
                       "[test3] [test2] me: this is a test of biffAddf 1 4.2\n");
        tmp = biffGet("test3");
        COMPARE(7);
    }

    airMopOkay(mop);
    exit(0);
}
Beispiel #19
0
int
unrrdu_histoMain(int argc, char **argv, char *me, hestParm *hparm) {
  hestOpt *opt = NULL;
  char *out, *err;
  Nrrd *nin, *nout, *nwght;
  int type, pret, blind8BitRange;
  unsigned int bins;
  double min, max;
  NrrdRange *range;
  airArray *mop;

  hestOptAdd(&opt, "b,bins", "num", airTypeUInt, 1, 1, &bins, NULL,
             "# of bins in histogram");
  hestOptAdd(&opt, "w,weight", "nweight", airTypeOther, 1, 1, &nwght, "",
             "how to weigh contributions to histogram.  By default "
             "(not using this option), the increment is one bin count per "
             "sample, but by giving a nrrd, the value in the nrrd at the "
             "corresponding location will be the bin count increment ",
             NULL, NULL, nrrdHestNrrd);
  hestOptAdd(&opt, "min,minimum", "value", airTypeDouble, 1, 1, &min, "nan",
             "Value at low end of histogram. Defaults to lowest value "
             "found in input nrrd.");
  hestOptAdd(&opt, "max,maximum", "value", airTypeDouble, 1, 1, &max, "nan",
             "Value at high end of histogram. Defaults to highest value "
             "found in input nrrd.");
  hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange,
             nrrdStateBlind8BitRange ? "true" : "false",
             "Whether to know the range of 8-bit data blindly "
             "(uchar is always [0,255], signed char is [-128,127]).");
  OPT_ADD_TYPE(type, "type to use for bins in output histogram", "uint");
  OPT_ADD_NIN(nin, "input nrrd");
  OPT_ADD_NOUT(out, "output nrrd");

  mop = airMopNew();
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);

  USAGE(_unrrdu_histoInfoL);
  PARSE();
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);

  nout = nrrdNew();
  airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
  
  /* If the input nrrd never specified min and max, then they'll be
     AIR_NAN, and nrrdRangeSafeSet will find them, and will do so
     according to blind8BitRange */
  range = nrrdRangeNew(min, max);
  airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways);
  nrrdRangeSafeSet(range, nin, blind8BitRange);
  if (nrrdHisto(nout, nin, range, nwght, bins, type)) {
    err = biffGet(NRRD);
    fprintf(stderr, "%s: error calculating histogram:\n%s", me, err);
    free(err);
    return 1;
  }

  SAVE(out, nout, NULL);

  airMopOkay(mop);
  return 0;
}
Beispiel #20
0
int
main(int argc, char *argv[]) {
    char *me, *err, *outS;
    limnCamera *cam;
    float matA[16], matB[16], winscale, edgeWidth[5];
    hestOpt *hopt=NULL;
    airArray *mop;
    limnObject *obj;
    limnLook *look;
    int lookIdx;
    limnWindow *win;
    int partIdx, wire, concave;
    Nrrd *nmap;

    mop = airMopNew();
    cam = limnCameraNew();
    airMopAdd(mop, cam, (airMopper)limnCameraNix, airMopAlways);

    me = argv[0];
    hestOptAdd(&hopt, "fr", "from point", airTypeDouble, 3, 3, cam->from,"4 4 4",
               "position of camera, used to determine view vector");
    hestOptAdd(&hopt, "at", "at point", airTypeDouble, 3, 3, cam->at, "0 0 0",
               "camera look-at point, used to determine view vector");
    hestOptAdd(&hopt, "up", "up vector", airTypeDouble, 3, 3, cam->up, "0 0 1",
               "camera pseudo-up vector, used to determine view coordinates");
    hestOptAdd(&hopt, "rh", NULL, airTypeInt, 0, 0, &(cam->rightHanded), NULL,
               "use a right-handed UVN frame (V points down)");
    hestOptAdd(&hopt, "or", NULL, airTypeInt, 0, 0, &(cam->orthographic), NULL,
               "use orthogonal projection");
    hestOptAdd(&hopt, "ur", "uMin uMax", airTypeDouble, 2, 2, cam->uRange,
               "-1 1", "range in U direction of image plane");
    hestOptAdd(&hopt, "vr", "vMin vMax", airTypeDouble, 2, 2, cam->vRange,
               "-1 1", "range in V direction of image plane");
    hestOptAdd(&hopt, "e", "envmap", airTypeOther, 1, 1, &nmap, NULL,
               "16checker-based environment map",
               NULL, NULL, nrrdHestNrrd);
    hestOptAdd(&hopt, "ws", "winscale", airTypeFloat, 1, 1, &winscale,
               "200", "world to points (PostScript) scaling");
    hestOptAdd(&hopt, "wire", NULL, airTypeInt, 0, 0, &wire, NULL,
               "just do wire-frame rendering");
    hestOptAdd(&hopt, "concave", NULL, airTypeInt, 0, 0, &concave, NULL,
               "use slightly buggy rendering method suitable for "
               "concave or self-occluding objects");
    hestOptAdd(&hopt, "wd", "5 widths", airTypeFloat, 5, 5, edgeWidth,
               "0.0 0.0 3.0 2.0 0.0",
               "width of edges drawn for five kinds of "
               "edges: back non-crease, back crease, "
               "silohuette, front crease, front non-crease");
    hestOptAdd(&hopt, "o", "output PS", airTypeString, 1, 1, &outS, "out.ps",
               "output file to render postscript into");
    hestParseOrDie(hopt, argc-1, argv+1, NULL,
                   me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
    airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
    airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

    cam->neer = -0.000000001;
    cam->dist = 0;
    cam->faar = 0.0000000001;
    cam->atRelative = AIR_TRUE;

    if (limnCameraUpdate(cam)) {
        fprintf(stderr, "%s: trouble:\n%s\n", me, err = biffGet(LIMN));
        free(err);
        return 1;
    }
    obj = limnObjectNew(10, AIR_TRUE);
    airMopAdd(mop, obj, (airMopper)limnObjectNix, airMopAlways);

    /* create limnLooks for diffuse (#0) and flat (#1) shading */
    lookIdx = airArrayLenIncr(obj->lookArr, 2);
    look = obj->look + lookIdx + 0;
    ELL_4V_SET(look->rgba, 1, 1, 1, 1);
    ELL_3V_SET(look->kads, 0, 1, 0);
    look->spow = 0;
    look = obj->look + lookIdx + 1;
    ELL_4V_SET(look->rgba, 1, 1, 1, 1);
    ELL_3V_SET(look->kads, 1, 0, 0);
    look->spow = 0;

    /* X axis: rod */
    partIdx = limnObjectCylinderAdd(obj, 0, 0, 16);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, 1, 0.2, 0.2);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 1.3, 0.0, 0.0);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    /* Y axis: rod + ball */
    partIdx = limnObjectCylinderAdd(obj, 0, 1, 16);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, 0.2, 1, 0.2);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 0.0, 1.3, 0.0);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    partIdx = limnObjectPolarSphereAdd(obj, 0, 0, 32, 16);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, 0.28, 0.28, 0.28);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 0.0, 2.6, 0.0);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    /* Z axis: rod + ball + ball */
    partIdx = limnObjectCylinderAdd(obj, 0, 2, 16);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, 0.2, 0.2, 1);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, 1.3);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    partIdx = limnObjectPolarSphereAdd(obj, 0, 1, 32, 16);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, 0.28, 0.28, 0.28);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, 2.6);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    partIdx = limnObjectPolarSphereAdd(obj, 0, 2, 32, 16);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, 0.28, 0.28, 0.28);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, 3.2);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    win = limnWindowNew(limnDevicePS);
    win->scale = winscale;
    win->ps.wireFrame = wire;
    win->ps.lineWidth[limnEdgeTypeBackFacet] = edgeWidth[0];
    win->ps.lineWidth[limnEdgeTypeBackCrease] = edgeWidth[1];
    win->ps.lineWidth[limnEdgeTypeContour] = edgeWidth[2];
    win->ps.lineWidth[limnEdgeTypeFrontCrease] = edgeWidth[3];
    win->ps.lineWidth[limnEdgeTypeFrontFacet] = edgeWidth[4];

    win->file = fopen(outS, "w");
    airMopAdd(mop, win, (airMopper)limnWindowNix, airMopAlways);

    if (limnObjectRender(obj, cam, win)
            || (concave
                ? limnObjectPSDrawConcave(obj, cam, nmap, win)
                : limnObjectPSDraw(obj, cam, nmap, win))) {
        airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
        fprintf(stderr, "%s: trouble:\n%s\n", me, err);
        airMopError(mop);
        return 1;
    }
    fclose(win->file);

    airMopOkay(mop);
    return 0;
}
Beispiel #21
0
int
main(int argc, char *argv[]) {
  int i;
  Nrrd *nrrd;
  double diff, idx, idx2, idx3, idx4, lo, hi, pos, pos2, pos3, pos4;

  AIR_UNUSED(argc);
  AIR_UNUSED(argv);
  if (nrrdAlloc_va(nrrd=nrrdNew(), nrrdTypeFloat, 2,
                   AIR_CAST(size_t, 4),
                   AIR_CAST(size_t, 4))) {
    printf("trouble:\n%s\n", biffGet(NRRD));
    exit(1);
  }
  nrrdAxisInfoSet_va(nrrd, nrrdAxisInfoMin, 10.0, 10.0);
  nrrdAxisInfoSet_va(nrrd, nrrdAxisInfoMax, 12.0, 12.0);
  nrrdAxisInfoSet_va(nrrd, nrrdAxisInfoCenter, nrrdCenterNode, nrrdCenterCell);

  idx = 0;
  printf("\n");
  pos = nrrdAxisInfoPos(nrrd, 0, idx);
  printf("pos(0, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 0, pos));
  pos = nrrdAxisInfoPos(nrrd, 1, idx);
  printf("pos(1, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 1, pos));

  idx = 1;
  printf("\n");
  pos = nrrdAxisInfoPos(nrrd, 0, idx);
  printf("pos(0, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 0, pos));
  pos = nrrdAxisInfoPos(nrrd, 1, idx);
  printf("pos(1, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 1, pos));

  idx = 2;
  printf("\n");
  pos = nrrdAxisInfoPos(nrrd, 0, idx);
  printf("pos(0, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 0, pos));
  pos = nrrdAxisInfoPos(nrrd, 1, idx);
  printf("pos(1, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 1, pos));

  idx = 0; idx2 = 0;
  printf("\n");
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 0, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 0, lo, hi);
  printf("range(0, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 1, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 1, lo, hi);
  printf("range(1, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);

  idx = 0; idx2 = 1;
  printf("\n");
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 0, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 0, lo, hi);
  printf("range(0, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 1, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 1, lo, hi);
  printf("range(1, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);

  idx = 1; idx2 = 0;
  printf("\n");
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 0, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 0, lo, hi);
  printf("range(0, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 1, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 1, lo, hi);
  printf("range(1, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);

  nrrdAxisInfoSet_va(nrrd, nrrdAxisInfoMin, 12.0, 12.0);
  nrrdAxisInfoSet_va(nrrd, nrrdAxisInfoMax, 10.0, 10.0);
  printf("\n(axis min,max flipped)\n");

  idx = 0;
  printf("\n");
  pos = nrrdAxisInfoPos(nrrd, 0, idx);
  printf("pos(0, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 0, pos));
  pos = nrrdAxisInfoPos(nrrd, 1, idx);
  printf("pos(1, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 1, pos));

  idx = 1;
  printf("\n");
  pos = nrrdAxisInfoPos(nrrd, 0, idx);
  printf("pos(0, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 0, pos));
  pos = nrrdAxisInfoPos(nrrd, 1, idx);
  printf("pos(1, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 1, pos));

  idx = 2;
  printf("\n");
  pos = nrrdAxisInfoPos(nrrd, 0, idx);
  printf("pos(0, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 0, pos));
  pos = nrrdAxisInfoPos(nrrd, 1, idx);
  printf("pos(1, %g) == %g --> %g\n",
         idx, pos, nrrdAxisInfoIdx(nrrd, 1, pos));

  idx = 0; idx2 = 0;
  printf("\n");
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 0, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 0, lo, hi);
  printf("range(0, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 1, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 1, lo, hi);
  printf("range(1, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);

  idx = 0; idx2 = 2;
  printf("\n");
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 0, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 0, lo, hi);
  printf("range(0, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 1, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 1, lo, hi);
  printf("range(1, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);

  idx = 2; idx2 = 0;
  printf("\n");
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 0, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 0, lo, hi);
  printf("range(0, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);
  nrrdAxisInfoPosRange(&lo, &hi, nrrd, 1, idx, idx2);
  nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 1, lo, hi);
  printf("range(1, %g -- %g) == (%g -- %g) --> (%g -- %g)\n",
         idx, idx2, lo, hi, idx3, idx4);

  nrrd->axis[0].center = nrrdCenterCell;
  nrrd->axis[0].size = 4;
  nrrd->axis[0].min = -4;
  nrrd->axis[0].max = 4;
  pos = 0;
  pos2 = 1;
  nrrdAxisInfoIdxRange(&idx, &idx2, nrrd, 0, pos, pos2);
  nrrdAxisInfoPosRange(&pos3, &pos4, nrrd, 0, idx, idx2);
  printf("min, max = %g, %g\n", nrrd->axis[0].min, nrrd->axis[0].max);
  printf("pos, pos2 = %g, %g\n", pos, pos2);
  printf("idx, idx2 = %g, %g\n", idx, idx2);
  printf("pos3, pos4 = %g, %g\n", pos3, pos4);
  exit(1);


  /* and now for random-ness */
  airSrandMT((int)airTime());
  nrrd->axis[0].center = nrrdCenterNode;
  nrrd->axis[0].center = nrrdCenterCell;
  for (i=0; i<=1000000; i++) {
    nrrd->axis[0].min = frand(-3.0, 3.0);
    nrrd->axis[0].max = frand(-3.0, 3.0);
    idx = frand(-3.0, 3.0);
    pos = nrrdAxisInfoPos(nrrd, 0, idx);
    diff = idx - nrrdAxisInfoIdx(nrrd, 0, pos);
    if (AIR_ABS(diff) > 0.00000001) { printf("PANIC 0\n"); exit(2); }
    pos = frand(-3.0, 3.0);
    idx = nrrdAxisInfoIdx(nrrd, 0, pos);
    diff = pos - nrrdAxisInfoPos(nrrd, 0, idx);
    if (AIR_ABS(diff) > 0.00000001) { printf("PANIC 1\n"); exit(2); }

    nrrd->axis[0].min = (int)frand(-3.0, 3.0);
    nrrd->axis[0].max = (int)frand(-3.0, 3.0);
    idx = (int)frand(-10.0, 10.0);
    idx2 = (int)frand(-10.0, 10.0);
    nrrdAxisInfoPosRange(&pos, &pos2, nrrd, 0, idx, idx2);
    nrrdAxisInfoIdxRange(&idx3, &idx4, nrrd, 0, pos, pos2);
    diff = AIR_ABS(idx - idx3) + AIR_ABS(idx2 - idx4);
    if (AIR_ABS(diff) > 0.00000001) { printf("PANIC 2\n"); exit(2); }
    pos = (int)frand(-3.0, 3.0);
    pos2 = (int)frand(-3.0, 3.0);
    nrrdAxisInfoIdxRange(&idx, &idx2, nrrd, 0, pos, pos2);
    nrrdAxisInfoPosRange(&pos3, &pos4, nrrd, 0, idx, idx2);
    diff = AIR_ABS(pos - pos3) + AIR_ABS(pos2 - pos4);
    if (AIR_ABS(diff) > 0.00000001) {
      printf("min, max = %g, %g\n", nrrd->axis[0].min, nrrd->axis[0].max);
      printf("pos, pos2 = %g, %g\n", pos, pos2);
      printf("idx, idx2 = %g, %g\n", idx, idx2);
      printf("pos3, pos4 = %g, %g\n", pos3, pos4);
      printf("PANIC (%d) 3 %g\n", (int)nrrd->axis[0].size, diff); exit(2);
    }
  }

  exit(0);
}
Beispiel #22
0
int
main() {
  char *tmp, *s1, *s2;
  biffMsg *msg1, *msg2;

  /*
  biffAdd("axis", "the first error axis");
  biffAdd("axis", "the second error axis");
  biffAdd("axis", "the third error axis");
  biffAdd("chard", "the first error chard");
  biffAdd("chard", "the second error chard");
  biffAdd("chard", "the third error chard");
  biffAdd("bingo", "zero-eth bingo message");
  biffMove("bingo", NULL, "chard");
  biffAdd("bingo", "the first error bingo");
  biffAdd("bingo", "the second bll boo boo boo error bingo");
  biffAdd("bingo", "the third error bingo");
  printf("%s\n", (tmp = biffGet("bingo")));
  free(tmp);
  biffDone("bingo");
  printf("%s\n", (tmp = biffGet("chard")));
  free(tmp);
  biffDone("chard");
  printf("%s\n", (tmp = biffGet("axis")));
  free(tmp);
  biffDone("axis");

  biffAdd("harold", "the first error harold");
  biffAdd("harold", "the second error harold");
  biffAdd("harold", "the third error harold");
  printf("%s\n", (tmp = biffGet("harold")));
  free(tmp);
  */

  biffAdd("axis", "the first error axis");
  biffAdd("axis", "the second error axis");
  biffAdd("axis", "the third error axis");
  biffAdd("axis", "the fourth error axis");
  biffAdd("axis", "the fifth error axis");
  printf("%s", (tmp = biffGet("axis")));
  free(tmp);
  biffDone("axis");

  biffAdd("axo", "the first error axis");
  biffAdd("axo", "the second error axis");
  biffAdd("axo", "the third error axis");
  biffAdd("axo", "the fourth error axis");
  biffAdd("axo", "the fifth error axis");
  printf("%s", (tmp = biffGetDone("axo")));
  free(tmp);

  printf("=================================\n");
  msg1 = biffMsgNew("roberts");
  biffMsgAdd(msg1, "biffMsgAdd hello, said roberts");
  biffMsgAddf(msg1, "biffMsgAddf: there's an int %d and a float %g",
              42, AIR_PI);
  s1 = biffMsgStrGet(msg1);
  printf("from msg1:\n%s", s1);
  s1 = airFree(s1);
  msg2 = biffMsgNew("sue");
  biffMsgAdd(msg2, "biffMsgAdd hi from sue");
  biffMsgAddf(msg2, "biffMsgAddf: another float %g", AIR_PI*AIR_PI);
  s2 = biffMsgStrGet(msg2);
  printf("from msg2:\n%s", s2);
  s2 = airFree(s2);
  biffMsgMovef(msg1, msg2, "biffMsgMovef: good int %d", 10);
  s1 = biffMsgStrGet(msg1);
  printf("from msg1:\n%s", s1);
  s1 = airFree(s1);
  printf("=================================\n");
  msg1 = biffMsgNix(msg1);
  msg2 = biffMsgNix(msg2);

  /*
  biffAddf("test", "%s: this is a test %d %f", "me", 1, 2.0);
  printf("%s\n", (tmp = biffGet("test")));
  free(tmp);
  biffDone("test");
  */

  exit(0);
}
int
main(int argc, char *argv[]) {
  char *iStr, *bStr, *pStr, *sStr, *gStr, *tStr;
  FILE *file;
  Nrrd *info2, *Bcpts;
  dirtTrnsf *trnsf;
  float sigma, gthresh;

  me = argv[0];
  if (argc != 6) 
    usage();
  bStr = argv[1];
  sStr = argv[2];
  gStr = argv[3];
  iStr = argv[4];
  tStr = argv[5];

  if (!(file = fopen(iStr, "r"))) {
    fprintf(stderr, "%s: couldn't open info2 %s for reading\n", me, iStr);
    usage();
  }
  if (!(info2 = nrrdNewRead(file))) {
    fprintf(stderr, "%s: trouble reading info 2%s:\n%s\n", me, iStr, 
            biffGet(NRRD));
    usage();
  }
  fclose(file);

  if (!(file = fopen(bStr, "r"))) {
    fprintf(stderr, "%s: couldn't open b(x) %s for reading\n", me, bStr);
    usage();
  }
  if (!(Bcpts = nrrdNewRead(file))) {
    fprintf(stderr, "%s: trouble reading b(x) %s:\n%s\n", me, 
            bStr, biffGet(NRRD));
    usage();
  }
  fclose(file);

  if (!strcmp(sStr, "nan")) {
    sigma = airNanf();
  }
  else {
    if (1 != sscanf(sStr, "%g", &sigma)) {
      fprintf(stderr, "%s: couldn't parse sigma %s\n", me, sStr);
      usage();
    }
  }
  if (1 != sscanf(gStr, "%g", &gthresh)) {
    fprintf(stderr, "%s: couldn't parse gthresh %s\n", me, gStr);
    usage();
  }

  trnsf = baneNewDirtTrnsf(Bcpts, sigma, gthresh, info2);
  if (!trnsf) {
    fprintf(stderr, "%s: trouble computing opacity functions:\n%s\n", me,
            biffGet(BANE));
    exit(1);
  }
  if (!(file = fopen(tStr, "w"))) {
    fprintf(stderr, "%s: couldn't open %s for writing\n", me, tStr);
    usage();
  }
  if (dirtTrnsfWrite(file, trnsf)) {
    fprintf(stderr, "%s: trouble writing trnsf to %s\n:%s\n", me, 
            tStr, biffGet(DIRT));
    usage();
  }
  fclose(file);

  nrrdNuke(info2);
  dirtNixTrnsf(trnsf);
  
  exit(0);
}