Пример #1
0
int
tkwbReadTemplate(char **tmplSP, char *filename) {
    char me[]="tkwbReadTemplate", err[BIFF_STRLEN];
    FILE *file;
    airArray *mop;

    mop = airMopNew();
    if (!( file = airFopen(filename, stdin, "rb") )) {
        sprintf(err, "%s: couldn't open %s: %s", me, filename, strerror(errno));
        biffAdd(TKWB, err);
        airMopError(mop);
        return 1;
    }
    airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

    if (tkwbReadFileToString(tmplSP, NULL, file, NULL)) {
        sprintf(err, "%s: couldn't read in template file %s", me, filename);
        biffAdd(TKWB, err);
        airMopError(mop);
        return 1;
    }

    airMopOkay(mop);
    return 0;
}
Пример #2
0
/*
******** nrrdSave
**
** save a given nrrd to a given filename, with cleverness to guess
** format if not specified by the caller
**
** currently, for NRRD format files, we play the detached header game
** whenever the filename ends in NRRD_EXT_NHDR, and when we play this
** game, the data file is ALWAYS header relative.
*/
int
nrrdSave(const char *filename, const Nrrd *nrrd, NrrdIoState *nio) {
    char me[]="nrrdSave", err[BIFF_STRLEN];
    FILE *file;
    airArray *mop;

    if (!(nrrd && filename)) {
        sprintf(err, "%s: got NULL pointer", me);
        biffAdd(NRRD, err);
        return 1;
    }
    mop = airMopNew();
    if (!nio) {
        nio = nrrdIoStateNew();
        if (!nio) {
            sprintf(err, "%s: couldn't alloc local NrrdIoState", me);
            biffAdd(NRRD, err);
            return 1;
        }
        airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways);
    }
    if (_nrrdEncodingMaybeSet(nio)
            || _nrrdFormatMaybeGuess(nrrd, nio, filename)) {
        sprintf(err, "%s: ", me);
        biffAdd(NRRD, err);
        airMopError(mop);
        return 1;
    }

    if (nrrdFormatNRRD == nio->format
            && airEndsWith(filename, NRRD_EXT_NHDR)) {
        nio->detachedHeader = AIR_TRUE;
        _nrrdSplitName(&(nio->path), &(nio->base), filename);
        /* nix the ".nhdr" suffix */
        nio->base[strlen(nio->base) - strlen(NRRD_EXT_NHDR)] = 0;
        /* nrrdFormatNRRD->write will do the rest */
    } else {
        nio->detachedHeader = AIR_FALSE;
    }

    if (!( file = airFopen(filename, stdout, "wb") )) {
        sprintf(err, "%s: couldn't fopen(\"%s\",\"wb\"): %s",
                me, filename, strerror(errno));
        biffAdd(NRRD, err);
        airMopError(mop);
        return 1;
    }
    airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

    if (nrrdWrite(file, nrrd, nio)) {
        sprintf(err, "%s:", me);
        biffAdd(NRRD, err);
        airMopError(mop);
        return 1;
    }

    airMopOkay(mop);
    return 0;
}
Пример #3
0
int
main(int argc, const char *argv[]) {
  const char *me;
  char *err, *outS;
  hestOpt *hopt=NULL;
  airArray *mop;

  limnPolyData *pld;
  FILE *file;
  Nrrd *nin;
  double thresh;
  int bitflag;

  me = argv[0];
  hestOptAdd(&hopt, "vi", "nin", airTypeOther, 1, 1, &nin, NULL,
             "input values",
             NULL, NULL, nrrdHestNrrd);
  hestOptAdd(&hopt, "pi", "lpld", airTypeOther, 1, 1, &pld, NULL,
             "input polydata",
             NULL, NULL, limnHestPolyDataLMPD);
  hestOptAdd(&hopt, "th", "thresh", airTypeDouble, 1, 1, &thresh, NULL,
             "threshold value");
  hestOptAdd(&hopt, "o", "output LMPD", airTypeString, 1, 1, &outS, "out.lmpd",
             "output file to save LMPD into");
  hestParseOrDie(hopt, argc-1, argv+1, NULL,
                 me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  mop = airMopNew();
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  bitflag = limnPolyDataInfoBitFlag(pld);
  fprintf(stderr, "!%s: bitflag = %d\n", me, bitflag);
  fprintf(stderr, "!%s: rgba %d,  norm %d,   tex2 %d\n", me,
          (1 << limnPolyDataInfoRGBA) & bitflag,
          (1 << limnPolyDataInfoNorm) & bitflag,
          (1 << limnPolyDataInfoTex2) & bitflag);

  file = airFopen(outS, stdout, "w");
  if (!file) {
    fprintf(stderr, "%s: couldn't open \"%s\" for writing", me, outS);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

  if (limnPolyDataClip(pld, nin, thresh)
      || limnPolyDataWriteLMPD(file, pld)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:\n%s\n", me, err);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
Пример #4
0
int
unrrduParseFile(void *ptr, char *str, char err[AIR_STRLEN_HUGE]) {
  char me[]="unrrduParseFile";
  FILE **fileP;

  if (!(ptr && str)) {
    sprintf(err, "%s: got NULL pointer", me);
    return 1;
  }
  fileP = (FILE **)ptr;
  if (!( *fileP = airFopen(str, stdin, "rb") )) {
    sprintf(err, "%s: fopen(\"%s\",\"rb\") failed: %s",
            me, str, strerror(errno));
    return 1;
  }
  return 0;
}
Пример #5
0
int
main(int argc, const char *argv[]) {
  const char *me;
  char *err, *outS;
  double eval[3], matA[9], matB[9], sval[3], uu[9], vv[9], escl[5],
    view[3];
  float matAf[9], matBf[16];
  float pp[3], qq[4], mR[9], len, gamma;
  float os, vs, rad, AB[2], ten[7];
  hestOpt *hopt=NULL;
  airArray *mop;
  limnObject *obj;
  limnLook *look; int lookRod, lookSoid;
  float kadsRod[3], kadsSoid[3];
  int gtype, partIdx=-1; /* sssh */
  int res;
  FILE *file;

  me = argv[0];
  hestOptAdd(&hopt, "sc", "evals", airTypeDouble, 3, 3, eval, "1 1 1",
             "original eigenvalues of tensor to be visualized");
  hestOptAdd(&hopt, "AB", "A, B exponents", airTypeFloat, 2, 2, AB, "nan nan",
             "Directly set the A, B parameters to the superquadric surface, "
             "over-riding the default behavior of determining them from the "
             "scalings \"-sc\" as superquadric tensor glyphs");
  hestOptAdd(&hopt, "os", "over-all scaling", airTypeFloat, 1, 1, &os, "1",
             "over-all scaling (multiplied by scalings)");
  hestOptAdd(&hopt, "vs", "view-dir scaling", airTypeFloat, 1, 1, &vs, "1",
             "scaling along view-direction (to show off bas-relief "
             "ambibuity of ellipsoids versus superquads)");
  hestOptAdd(&hopt, "es", "extra scaling", airTypeDouble, 5, 5, escl,
             "2 1 0 0 1", "extra scaling specified with five values "
             "0:tensor|1:geometry|2:none vx vy vz scaling");
  hestOptAdd(&hopt, "fr", "from (eye) point", airTypeDouble, 3, 3, &view,
             "4 4 4", "eye point, needed for non-unity \"-vs\"");
  hestOptAdd(&hopt, "gamma", "superquad sharpness", airTypeFloat, 1, 1,
             &gamma, "0",
             "how much to sharpen edges as a "
             "function of differences between eigenvalues");
  hestOptAdd(&hopt, "g", "glyph shape", airTypeEnum, 1, 1, &gtype, "sqd",
             "glyph to use; not all are implemented here",
             NULL, tenGlyphType);
  hestOptAdd(&hopt, "pp", "x y z", airTypeFloat, 3, 3, pp, "0 0 0",
             "transform: rotation identified by"
             "location in quaternion quotient space");
  hestOptAdd(&hopt, "r", "radius", airTypeFloat, 1, 1, &rad, "0.015",
             "black axis cylinder radius (or 0.0 to not drawn these)");
  hestOptAdd(&hopt, "res", "resolution", airTypeInt, 1, 1, &res, "25",
             "tesselation resolution for both glyph and axis cylinders");
  hestOptAdd(&hopt, "pg", "ka kd ks", airTypeFloat, 3, 3, kadsSoid,
             "0.2 0.8 0.0",
             "phong coefficients for glyph");
  hestOptAdd(&hopt, "pr", "ka kd ks", airTypeFloat, 3, 3, kadsRod, "1 0 0",
             "phong coefficients for black rods (if being drawn)");
  hestOptAdd(&hopt, "o", "output OFF", airTypeString, 1, 1, &outS, "out.off",
             "output file to save OFF into");
  hestParseOrDie(hopt, argc-1, argv+1, NULL,
                 me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  mop = airMopNew();
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  obj = limnObjectNew(1000, AIR_TRUE);
  airMopAdd(mop, obj, (airMopper)limnObjectNix, airMopAlways);

  if (!( 0 == escl[0] || 1 == escl[0] || 2 == escl[0] )) {
    fprintf(stderr, "%s: escl[0] %g not 0, 1 or 2\n", me, escl[0]);
    airMopError(mop); return 1;
  }
  if (!(tenGlyphTypeBox == gtype ||
        tenGlyphTypeSphere == gtype ||
        tenGlyphTypeSuperquad == gtype)) {
    fprintf(stderr, "%s: got %s %s, but here only do %s, %s, or %s\n", me,
            tenGlyphType->name,
            airEnumStr(tenGlyphType, gtype),
            airEnumStr(tenGlyphType, tenGlyphTypeBox),
            airEnumStr(tenGlyphType, tenGlyphTypeSphere),
            airEnumStr(tenGlyphType, tenGlyphTypeSuperquad));
    airMopError(mop); return 1;
  }

  /* create limnLooks for glyph and for rods */
  lookSoid = limnObjectLookAdd(obj);
  look = obj->look + lookSoid;
  ELL_4V_SET(look->rgba, 1, 1, 1, 1);
  ELL_3V_COPY(look->kads, kadsSoid);

  look->spow = 0;
  lookRod = limnObjectLookAdd(obj);
  look = obj->look + lookRod;
  ELL_4V_SET(look->rgba, 0, 0, 0, 1);
  ELL_3V_COPY(look->kads, kadsRod);
  look->spow = 0;

  ELL_3M_IDENTITY_SET(matA); /* A = I */
  ELL_3V_SCALE(eval, os, eval);
  ELL_3M_SCALE_SET(matB, eval[0], eval[1], eval[2]); /* B = diag(eval) */
  ell_3m_post_mul_d(matA, matB); /* A = B*A = diag(eval) */

  if (0 == escl[0]) {
    scalingMatrix(matB, escl + 1, escl[4]);
    ell_3m_post_mul_d(matA, matB);
  }

  if (1 != vs) {
    if (!ELL_3V_LEN(view)) {
      fprintf(stderr, "%s: need non-zero view for vs %g != 1\n", me, vs);
      airMopError(mop); return 1;
    }
    scalingMatrix(matB, view, vs);
    /* the scaling along the view direction is a symmetric matrix,
       but applying that scaling to the symmetric input tensor
       is not necessarily symmetric */
    ell_3m_post_mul_d(matA, matB);  /* A = B*A */
  }
  /* so we do an SVD to get rotation U and the scalings sval[] */
  /* U * diag(sval) * V */
  ell_3m_svd_d(uu, sval, vv, matA, AIR_TRUE);

  /*
  fprintf(stderr, "%s: ____________________________________\n", me);
  fprintf(stderr, "%s: mat = \n", me);
  ell_3m_print_d(stderr, matA);
  fprintf(stderr, "%s: uu = \n", me);
  ell_3m_print_d(stderr, uu);
  ELL_3M_TRANSPOSE(matC, uu);
  ELL_3M_MUL(matB, uu, matC);
  fprintf(stderr, "%s: uu * uu^T = \n", me);
  ell_3m_print_d(stderr, matB);
  fprintf(stderr, "%s: sval = %g %g %g\n", me, sval[0], sval[1], sval[2]);
  fprintf(stderr, "%s: vv = \n", me);
  ell_3m_print_d(stderr, vv);
  ELL_3M_MUL(matB, vv, vv);
  fprintf(stderr, "%s: vv * vv^T = \n", me);
  ELL_3M_TRANSPOSE(matC, vv);
  ELL_3M_MUL(matB, vv, matC);
  ell_3m_print_d(stderr, matB);
  ELL_3M_IDENTITY_SET(matA);
  ell_3m_pre_mul_d(matA, uu);
  ELL_3M_SCALE_SET(matB, sval[0], sval[1], sval[2]);
  ell_3m_pre_mul_d(matA, matB);
  ell_3m_pre_mul_d(matA, vv);
  fprintf(stderr, "%s: uu * diag(sval) * vv = \n", me);
  ell_3m_print_d(stderr, matA);
  fprintf(stderr, "%s: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", me);
  */

  /* now create symmetric matrix out of U and sval */
  /* A = I */
  ELL_3M_IDENTITY_SET(matA);
  ell_3m_pre_mul_d(matA, uu);   /* A = A*U = I*U = U */
  ELL_3M_SCALE_SET(matB, sval[0], sval[1], sval[2]); /* B = diag(sval) */
  ell_3m_pre_mul_d(matA, matB); /* A = U*diag(sval) */
  ELL_3M_TRANSPOSE(matB, uu);
  ell_3m_pre_mul_d(matA, matB); /* A = U*diag(sval)*U^T */
  TEN_M2T(ten, matA);

  partIdx = soidDoit(obj, lookSoid,
                     gtype, gamma, res,
                     (AIR_EXISTS(AB[0]) && AIR_EXISTS(AB[1])) ? AB : NULL,
                     ten);

  if (1 == escl[0]) {
    scalingMatrix(matB, escl + 1, escl[4]);
    ELL_43M_INSET(matBf, matB);
    limnObjectPartTransform(obj, partIdx, matBf);
  }
  /* this is a rotate on the geomtry; nothing to do with the tensor */
  ELL_4V_SET(qq, 1, pp[0], pp[1], pp[2]);
  ELL_4V_NORM(qq, qq, len);
  ell_q_to_3m_f(mR, qq);
  ELL_43M_INSET(matBf, mR);
  limnObjectPartTransform(obj, partIdx, matBf);

  if (rad) {
    partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, (1-eval[0])/2, rad, rad);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, (1+eval[0])/2, 0.0, 0.0);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, (1-eval[0])/2, rad, rad);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, -(1+eval[0])/2, 0.0, 0.0);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, rad, (1-eval[1])/2, rad);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, 0.0, (1+eval[1])/2, 0.0);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, rad, (1-eval[1])/2, rad);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, 0.0, -(1+eval[1])/2, 0.0);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, rad, rad, (1-eval[2])/2);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, 0.0, 0.0, (1+eval[2])/2);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, rad, rad, (1-eval[2])/2);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, 0.0, 0.0, -(1+eval[2])/2);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);
  }

  file = airFopen(outS, stdout, "w");
  airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

  if (limnObjectWriteOFF(file, obj)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:\n%s\n", me, err);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
Пример #6
0
int
main(int argc, char *argv[]) {
  char *me, *outS;
  hestOpt *hopt;
  hestParm *hparm;
  airArray *mop;
  
  double tval[6], ABC[3], geom[3], rnth[3], RA, norm, mu2, tmpr=0, tmpa=0,
    xroot[3], yroot[3], bbox[4], htick, htth, psc;
  wheelPS wps;
  int correct, labels, drawRA;

  me = argv[0];
  mop = airMopNew();
  hparm = hestParmNew();
  hparm->elideMultipleNonExistFloatDefault = AIR_TRUE;
  hopt = NULL;
  airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);
  hestOptAdd(&hopt, "t", "a b c d e f", airTypeDouble, 6, 6, tval,
             "nan nan nan nan nan nan nan",
             "six values of symmetric tensors");
  hestOptAdd(&hopt, "ABC", "A B C", airTypeDouble, 3, 3, ABC, "nan nan nan",
             "directly give coefficients of cubic polynomial "
             "(and override info from \"-t\")");
  hestOptAdd(&hopt, "g", "c rad th", airTypeDouble, 3, 3, geom, "nan nan nan",
             "directly give center, radius, and angle (in degrees) of wheel "
             "(and override info from \"-t\" and \"-ABC\"");
  hestOptAdd(&hopt, "p", "RA norm th", airTypeDouble, 3, 3, rnth, 
             "nan nan nan",
             "directly give RA, norm, and angle (in degrees) of tensor "
             "(and override info from \"-t\", \"-ABC\", and \"-geom\"");
  hestOptAdd(&hopt, "correct", NULL, airTypeInt, 0, 0, &correct, NULL,
             "when using \"-g\", be honest about what the estimated "
             "acos(sqrt(2)*skew)/3 is going to be");
  hestOptAdd(&hopt, "labels", NULL, airTypeInt, 0, 0, &labels, NULL,
             "put little labels on things; fix with psfrag in LaTeX");
  hestOptAdd(&hopt, "RA", NULL, airTypeInt, 0, 0, &drawRA, NULL,
             "draw extra geometry associated with RA");
  hestOptAdd(&hopt, "htick", "pos", airTypeDouble, 1, 1, &htick, "nan",
             "location of single tick mark on horizontal axis");
  hestOptAdd(&hopt, "htth", "thick", airTypeDouble, 1, 1, &htth, "3",
             "thickness of horizontal tick");
  hestOptAdd(&hopt, "bb", "bbox", airTypeDouble, 4, 4, bbox, 
             "nan nan nan nan", "bounding box, in world space around the "
             "region of the graph that should be drawn to EPS");
  hestOptAdd(&hopt, "ysc", "scale", airTypeDouble, 1, 1, &(wps.yscale), "0.5",
             "scaling on Y axis for drawing graph of characteristic "
             "polynomial, or \"0\" to turn this off.");
  hestOptAdd(&hopt, "psc", "scale", airTypeDouble, 1, 1, &psc, "100",
             "scaling from world space to PostScript points");
  hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, "-",
             "file to write EPS output to");
  hestParseOrDie(hopt, argc-1, argv+1, hparm,
                 me, wheelInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  if (!(wps.file = airFopen(outS, stdout, "wb"))) {
    fprintf(stderr, "%s: couldn't open output file\n", me);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, wps.file, (airMopper)airFclose, airMopAlways);

  if (AIR_EXISTS(rnth[0])) {
    RA = rnth[0];
    norm = rnth[1];
    mu2 = (norm*norm/3)*(2*RA*RA/(1 + 2*RA*RA));
    geom[0] = sqrt(mu2)/(sqrt(2)*RA);
    geom[1] = sqrt(2*mu2);
    geom[2] = rnth[2];
    wheelGeomToRoot(xroot, yroot, geom);
    wheelGeomToABC(ABC, geom[0], geom[1], geom[2]);
  } else if (AIR_EXISTS(geom[0])) {
    wheelGeomToRoot(xroot, yroot, geom);
    if (correct) {
      tval[0] = xroot[0];
      tval[1] = tval[2] = 0;
      tval[3] = xroot[1];
      tval[4] = 0;
      tval[5] = xroot[2];
      wheelTenToGeom(geom,
                     tval[0], tval[1], tval[2], tval[3], tval[4], tval[5]);
      wheelGeomToRoot(xroot, yroot, geom);
    }
    wheelGeomToABC(ABC, geom[0], geom[1], geom[2]);
    wheelGeomToRNTH(rnth, geom[0], geom[1], geom[2]);
  } else if (AIR_EXISTS(ABC[0])) {
    wheelABCToGeom(geom, ABC[0], ABC[1], ABC[2]);
    wheelGeomToRNTH(rnth, geom[0], geom[1], geom[2]);
    wheelGeomToRoot(xroot, yroot, geom);
  } else {
    wheelTenToGeom(geom, tval[0], tval[1], tval[2], tval[3], tval[4], tval[5]);
    wheelGeomToRoot(xroot, yroot, geom);
    wheelGeomToRNTH(rnth, geom[0], geom[1], geom[2]);
    wheelGeomToABC(ABC, geom[0], geom[1], geom[2]);
  }
  fprintf(stderr, "%s: RNTH: %g %g %g\n", me, rnth[0], rnth[1], rnth[2]);
  fprintf(stderr, "%s: ABC: %g %g %g\n", me, ABC[0], ABC[1], ABC[2]);
  fprintf(stderr, "%s: xroot: %g %g %g\n",
          me, xroot[0], xroot[1], xroot[2]);
  fprintf(stderr, "%s: geom: %g %g %g\n", me, geom[0], geom[1], geom[2]);

  if (!AIR_EXISTS(bbox[0])) {
    bbox[0] = geom[0] - 1.2*geom[1];
    bbox[1] = - 1.2*geom[1];
    bbox[2] = geom[0] + 1.2*geom[1];
    bbox[3] = + 1.2*geom[1];
    fprintf(stderr, "%s: bbox %g %g %g %g\n", me,
            bbox[0], bbox[1], bbox[2], bbox[3]);
  }
  wps.psc = psc;
  ELL_4V_COPY(wps.bbox, bbox);
  wheelPreamble(&wps);

  /* graph */
  if (wps.yscale) {
    wheelWidth(&wps, 4);
    wheelGray(&wps, 0.5);
    wheelGraph(&wps, xroot[0], xroot[1], xroot[2]);
  }

  /* axis */
  wheelWidth(&wps, 2);
  wheelGray(&wps, 0.0);
  wheelLine(&wps, bbox[0], 0, bbox[2], 0);

  /* circle */
  wheelWidth(&wps, 3);
  wheelCircle(&wps, geom[0], 0, geom[1]);

  /* spokes */
  wheelWidth(&wps, 4);
  wheelLine(&wps, geom[0], 0, xroot[0], yroot[0]);
  wheelLine(&wps, geom[0], 0, xroot[1], yroot[1]);
  wheelLine(&wps, geom[0], 0, xroot[2], yroot[2]);
  
  /* dots at spoke ends */
  wheelDot(&wps, xroot[0], yroot[0], 0.025*geom[1]);
  wheelDot(&wps, xroot[1], yroot[1], 0.025*geom[1]);
  wheelDot(&wps, xroot[2], yroot[2], 0.025*geom[1]);

  /* lines from dots to roots */
  wheelWidth(&wps, 2);
  fprintf(wps.file, "gsave\n");
  fprintf(wps.file, "[2 4] 0 setdash\n");
  wheelLine(&wps, xroot[0], 0, xroot[0], yroot[0]);
  wheelLine(&wps, xroot[1], 0, xroot[1], yroot[1]);
  wheelLine(&wps, xroot[2], 0, xroot[2], yroot[2]);
  fprintf(wps.file, "grestore\n");

  /* tickmarks */
  wheelWidth(&wps, 6);
  wheelLine(&wps, xroot[0], -0.02*geom[1], xroot[0], 0.02*geom[1]);
  wheelLine(&wps, xroot[1], -0.02*geom[1], xroot[1], 0.02*geom[1]);
  wheelLine(&wps, xroot[2], -0.02*geom[1], xroot[2], 0.02*geom[1]);
  if (AIR_EXISTS(htick)) {
    wheelWidth(&wps, htth);
    wheelLine(&wps, htick, -0.04, htick, 0.04);
  }

  /* RA angle */
  if (drawRA) {
    wheelWidth(&wps, 3);
    wheelLine(&wps, 0.0, 0.0, geom[0], geom[1]);
    wheelWidth(&wps, 2);
    fprintf(wps.file, "gsave\n");
    fprintf(wps.file, "[2 4] 0 setdash\n");
    wheelLine(&wps, geom[0], geom[1], geom[0], 0);
    fprintf(wps.file, "grestore\n");
  }

  /* labels, if wanted */
  if (labels) {
    fprintf(wps.file, "/Helvetica findfont 20 scalefont setfont\n");
    wheelLabel(&wps, geom[0], 0, "center");
    wheelLine(&wps, geom[0], -0.02*geom[1], geom[0], 0.02*geom[1]);
    wheelLabel(&wps, (geom[0] + xroot[0])/1.8, yroot[0]/1.8, "radius");
    wheelWidth(&wps, 2);
    wheelArc(&wps, geom[0], 0, geom[1]/2, 0, geom[2]);
    wheelLabel(&wps, geom[0] + geom[1]*cos(AIR_PI*geom[2]/180/2)/2.5, 
               geom[1]*sin(AIR_PI*geom[2]/180/2)/2.5, "theta");
    if (drawRA) {
      tmpr = sqrt(geom[0]*geom[0] + geom[1]*geom[1]);
      tmpa = atan(2.0*rnth[0]);
      wheelWidth(&wps, 2);
      wheelArc(&wps, 0, 0, 0.2*tmpr, 0, 180*tmpa/AIR_PI);
      wheelLabel(&wps, 0.2*tmpr*cos(tmpa/2), 0.2*tmpr*sin(tmpa/2), "phi");
    }
    wheelLabel(&wps, xroot[0], yroot[0], "spoke0");
    wheelLabel(&wps, xroot[1], yroot[1], "spoke-");
    wheelLabel(&wps, xroot[2], yroot[2], "spoke+");
    wheelLabel(&wps, xroot[0], 0, "root0");
    wheelLabel(&wps, xroot[1], 0, "root-");
    wheelLabel(&wps, xroot[2], 0, "root+");
  }

  wheelEpilog(&wps);

  airMopOkay(mop);
  exit(0);
}
Пример #7
0
int
main(int argc, char *argv[]) {
  char *me, *kernS[2], *minS, *stepS, *maxS, *outS, *err, kstr[AIR_STRLEN_LARGE];
  const NrrdKernel *kern[2];
  NrrdKernelSpec *ksp[2];
  double parm[NRRD_KERNEL_PARMS_NUM], min, step, max, integral,
    *dom_d, *ran_d;
  float *dom_f, *ran_f, val, r_f, r_d;
  FILE *fout;
  int i, len;
  airArray *mop;
  unsigned int kii;

  me = argv[0];
  if (!( 6 == argc || 7 == argc )) {
    usage(me);
  }
  kernS[0] = argv[1];
  minS = argv[2];
  stepS = argv[3];
  maxS = argv[4];
  outS = argv[5];
  if (7 == argc) {
    kernS[1] = argv[6];
  } else {
    kernS[1] = NULL;
  }

  if (3 != (sscanf(minS, "%lf", &min) +
            sscanf(stepS, "%lf", &step) +
            sscanf(maxS, "%lf", &max))) {
    fprintf(stderr, "%s: couldn't parse \"%s\", \"%s\", \"%s\" as 3 doubles\n",
            me, minS, stepS, maxS);
    exit(1);
  }

  mop = airMopNew();
  for (kii=0; kii<=(kernS[1] ? 1 : 0); kii++) {
    if (nrrdKernelParse(&(kern[kii]), parm, kernS[kii])) {
      airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways);
      fprintf(stderr, "%s: (kii %u) trouble:\n%s\n", me, kii, err);
      airMopError(mop);
      exit(1);
    }
    ksp[kii] = nrrdKernelSpecNew();
    airMopAdd(mop, ksp[kii], (airMopper)nrrdKernelSpecNix, airMopAlways);
    nrrdKernelSpecSet(ksp[kii], kern[kii], parm);
    if (nrrdKernelSpecSprint(kstr, ksp[kii])) {
      airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways);
      fprintf(stderr, "%s: trouble:\n%s\n", me, err);
      airMopError(mop);
      exit(1);
    }
    fprintf(stderr, "%s: printed kernel as \"%s\"\n", me, kstr);
    if (!( min <= -kern[kii]->support(parm)
           && max >= kern[kii]->support(parm) )) {
      fprintf(stderr, "%s: WARNING: support=%g => lower min (%g) or raise max (%g)\n",
              me, kern[kii]->support(parm), min, max);
    }
    fprintf(stderr, "%s: support(%s) = %g\n", me, kstr, kern[kii]->support(parm));
  }

  /* see how many values are in the interval */
  len = 0;
  for (val=min; val<=max; val+=step) {
    len++;
  }
  /* allocate domain and range for both float and double */
  if (!( (dom_d = (double *)calloc(len, sizeof(double))) &&
         (ran_d = (double *)calloc(len, sizeof(double))) &&
         (dom_f = (float *)calloc(len, sizeof(float))) &&
         (ran_f = (float *)calloc(len, sizeof(float))) )) {
    fprintf(stderr, "%s: PANIC: couldn't allocate buffers\n", me);
    exit(1);
  }
  airMopAdd(mop, dom_d, airFree, airMopAlways);
  airMopAdd(mop, ran_d, airFree, airMopAlways);
  airMopAdd(mop, dom_f, airFree, airMopAlways);
  airMopAdd(mop, ran_f, airFree, airMopAlways);
  /* set values in both domains */
  i=0;
  for (val=min; val<=max; val+=step) {
    /* note that the value stored in dom_d[i] is only a
       single-precision float, so that it is really equal to dom_f[i] */
    dom_d[i] = val;
    dom_f[i] = val;
    i++;
  }
  /* do the vector evaluations */
  kern[0]->evalN_f(ran_f, dom_f, len, parm);
  kern[0]->evalN_d(ran_d, dom_d, len, parm);
  /* do the single evaluations, and make sure everything agrees */
  i = 0;
  integral = 0;
  for (val=min; val<=max; val+=step) {
    /* compare two single evaluations */
    r_f = kern[0]->eval1_f(val, parm);
    r_d = kern[0]->eval1_d(val, parm);
    if (!CLOSE(r_f,r_d, 0.00001)) {
      fprintf(stderr, "%s: (eval1_f(%g)== %f) != (eval1_d(%g)== %f)\n",
              me, val, r_f, val, r_d);
    }
    /* compare single float with vector float */
    if (!CLOSE(r_f,ran_f[i], 0.00001)) {
      fprintf(stderr, "%s: (eval1_f(%g)== %f) != (evalN_f[%d]== %f)\n",
              me, val, r_f, i, ran_f[i]);
    }
    /* compare single float with vector double */
    r_d = ran_d[i];
    if (!CLOSE(r_f,r_d, 0.00001)) {
      fprintf(stderr, "%s: (eval1_f(%g)== %f) != (evalN_d[%d]== %f)\n",
              me, val, r_f, i, r_d);
    }
    integral += step*ran_d[i];
    /* possibly check on given derivatives */
    if (kern[1]) {
      double numd;
      numd = (kern[0]->eval1_d(val+step/2, parm)
              - kern[0]->eval1_d(val-step/2, parm))/step;
      if (!CLOSE(numd, kern[1]->eval1_d(val+step, parm), 0.005)) {
        fprintf(stderr, "%s: |numerical f'(%g) %g - true %g| = %g > 0.005\n",
                me, val, numd, kern[1]->eval1_d(val+step, parm),
                fabs(numd - kern[1]->eval1_d(val+step, parm)));
        /* exit(1); */
      }
    }
    i++;
  }
  if (!CLOSE(integral, kern[0]->integral(parm), 0.0005)) {
    fprintf(stderr, "%s: HEY HEY HEY HEY HEY HEY!\n", me);
    fprintf(stderr,
            "%s: discrete integral %f != %f\n", me, integral, kern[0]->integral(parm));
    /* exit(1); */
  }

  /* it all checks out; write the file */
  if (!(fout = airFopen(outS, stdout, "w"))) {
    fprintf(stderr, "%s: couldn't open \"%s\" for writing\n", me, outS);
    exit(1);
  }
  for (i=0; i<=len-1; i++) {
    fprintf(fout, "%g %g\n", dom_f[i], ran_f[i]);
  }
  fclose(fout);

  airMopOkay(mop);
  exit(0);
}
Пример #8
0
/*
** this is responsible for the header-relative path processing
**
** NOTE: if the filename is "-", then because it does not start with '/',
** it would normally be prefixed by nio->path, so it needs special handling
**
** NOTE: this should work okay with nio->headerStringRead, I think ...
*/
int
nrrdIoStateDataFileIterNext(FILE **fileP, NrrdIoState *nio, int reading) {
  char me[]="nrrdIoStateDataFileIterNext", *err;
  char *fname=NULL;
  int ii, needPath;
  unsigned int num, fi;
  size_t maxl;
  airArray *mop;

  mop = airMopNew();
  airMopAdd(mop, (void*)fileP, (airMopper)airSetNull, airMopOnError);

  if (!fileP) {
    if ((err = (char*)malloc(BIFF_STRLEN))) {
      sprintf(err, "%s: got NULL pointer", me);
      biffAdd(NRRD, err); free(err);
    }
    airMopError(mop); return 1;
  }
  if (!_nrrdDataFNNumber(nio)) {
    if ((err = (char*)malloc(BIFF_STRLEN))) {
      sprintf(err, "%s: there appear to be zero datafiles!", me);
      biffAdd(NRRD, err); free(err);
    }
    airMopError(mop); return 1;
  }

  nio->dataFNIndex++;
  if (nio->dataFNIndex >= (int)_nrrdDataFNNumber(nio)) {
    /* there is no next data file, but we don't make that an error */
    nio->dataFNIndex = _nrrdDataFNNumber(nio);
    airMopOkay(mop);
    *fileP = NULL;
    return 0;
  }

  /* HEY: some of this error checking is done far more often than needed */
  if (nio->dataFNFormat || nio->dataFNArr->len) {
    needPath = AIR_FALSE;
    maxl = 0;
    if (nio->dataFNFormat) {
      needPath = _NEED_PATH(nio->dataFNFormat);
      /* assuming 10-digit integers is plenty big */
      maxl = 10 + strlen(nio->dataFNFormat);
    } else {
      for (fi=0; fi<nio->dataFNArr->len; fi++) {
        needPath |= _NEED_PATH(nio->dataFN[fi]);
        maxl = AIR_MAX(maxl, strlen(nio->dataFN[fi]));
      }
    }
    if (needPath && !airStrlen(nio->path)) {
      if ((err = (char*)malloc(BIFF_STRLEN))) {
        sprintf(err, "%s: need nio->path for header-relative datafiles", me);
        biffAdd(NRRD, err); free(err);
      }
      airMopError(mop); return 1;
    }
    fname = (char*)malloc(airStrlen(nio->path) + strlen("/") + maxl + 1);
    if (!fname) {
      if ((err = (char*)malloc(BIFF_STRLEN))) {
        sprintf(err, "%s: couldn't allocate filename buffer", me);
        biffAdd(NRRD, err); free(err);
      }
      airMopError(mop); return 1;
    }
    airMopAdd(mop, fname, airFree, airMopAlways);
  }

  if (nio->dataFNFormat) {
    /* ---------------------------------------------------------- */
    /* --------- base.%d <min> <max> <step> [<dim>] ------------- */
    /* ---------------------------------------------------------- */
    num = 0;
    for (ii = nio->dataFNMin; 
         ((nio->dataFNStep > 0 && ii <= nio->dataFNMax)
          || (nio->dataFNStep < 0 && ii >= nio->dataFNMax));
         ii += nio->dataFNStep) {
      if ((int)num == nio->dataFNIndex) {  /* HEY scrutinize cast */
        break;
      }
      num += 1;
    }
    if (_NEED_PATH(nio->dataFNFormat)) {
      strcpy(fname, nio->path);
      strcat(fname, "/");
      sprintf(fname + strlen(nio->path) + strlen("/"), nio->dataFNFormat, ii);
    } else {
      sprintf(fname, nio->dataFNFormat, ii);
    }
  } else if (nio->dataFNArr->len) {
    /* ---------------------------------------------------------- */
    /* ------------------- LIST or single ----------------------- */
    /* ---------------------------------------------------------- */
    if (_NEED_PATH(nio->dataFN[nio->dataFNIndex])) {
      sprintf(fname, "%s/%s", nio->path, nio->dataFN[nio->dataFNIndex]);
    } else {
      strcpy(fname, nio->dataFN[nio->dataFNIndex]);
    }
  }
  /* else data file is attached */
  
  if (nio->dataFNFormat || nio->dataFNArr->len) {
    *fileP = airFopen(fname, reading ? stdin : stdout, reading ? "rb" : "wb");
    if (!(*fileP)) {
      if ((err = (char*)malloc(strlen(fname) + BIFF_STRLEN))) {
        sprintf(err, "%s: couldn't open \"%s\" (data file %d of %d) for %s",
                me, fname, nio->dataFNIndex+1, (int)_nrrdDataFNNumber(nio),
                reading ? "reading" : "writing");
        biffAdd(NRRD, err); free(err);
      }
      airMopError(mop); return 1;
    }
  } else {
    /* data file is attached */
    if (nio->headerStringRead) {
      /* except we were never reading from a file to begin with, but this
         isn't an error */
      *fileP = NULL;
    } else {
      *fileP = nio->headerFile;
    }
  }
  
  airMopOkay(mop);
  return 0;
}
Пример #9
0
int
main(int argc, const char *argv[]) {
  const char *me;
  char *err, *outS;
  double scale[3], matA[9], matB[9], matC[9], sval[3], uu[9], vv[9];
  float matAf[9], matBf[16];
  float p[3], q[4], mR[9], len, gamma;
  float os, vs, rad, AB[2], ten[7], view[3];
  hestOpt *hopt=NULL;
  airArray *mop;
  limnObject *obj;
  limnLook *look; int lookRod, lookSoid;
  int partIdx=-1; /* sssh */
  int res, sphere;
  FILE *file;

  me = argv[0];
  hestOptAdd(&hopt, "sc", "scalings", airTypeDouble, 3, 3, scale, "1 1 1",
             "axis-aligned scaling to do on ellipsoid");
  hestOptAdd(&hopt, "AB", "A, B exponents", airTypeFloat, 2, 2, AB, "nan nan",
             "Directly set the A, B parameters to the superquadric surface, "
             "over-riding the default behavior of determining them from the "
             "scalings \"-sc\" as superquadric tensor glyphs");
  hestOptAdd(&hopt, "os", "over-all scaling", airTypeFloat, 1, 1, &os, "1",
             "over-all scaling (multiplied by scalings)");
  hestOptAdd(&hopt, "vs", "over-all scaling", airTypeFloat, 1, 1, &vs, "1",
             "scaling along view-direction (to show off bas-relief "
             "ambibuity of ellipsoids versus superquads)");
  hestOptAdd(&hopt, "fr", "from (eye) point", airTypeFloat, 3, 3, &view,
             "4 4 4", "eye point, needed for non-unity \"-vs\"");
  hestOptAdd(&hopt, "gamma", "superquad sharpness", airTypeFloat, 1, 1,
             &gamma, "0",
             "how much to sharpen edges as a "
             "function of differences between eigenvalues");
  hestOptAdd(&hopt, "sphere", NULL, airTypeInt, 0, 0, &sphere, NULL,
             "use a sphere instead of a superquadric");
  hestOptAdd(&hopt, "p", "x y z", airTypeFloat, 3, 3, p, "0 0 0",
             "location in quaternion quotient space");
  hestOptAdd(&hopt, "r", "radius", airTypeFloat, 1, 1, &rad, "0.015",
             "black axis cylinder radius (or 0.0 to not drawn these)");
  hestOptAdd(&hopt, "res", "resolution", airTypeInt, 1, 1, &res, "25",
             "tesselation resolution for both glyph and axis cylinders");
  hestOptAdd(&hopt, "o", "output OFF", airTypeString, 1, 1, &outS, "out.off",
             "output file to save OFF into");
  hestParseOrDie(hopt, argc-1, argv+1, NULL,
                 me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  mop = airMopNew();
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  obj = limnObjectNew(1000, AIR_TRUE);
  airMopAdd(mop, obj, (airMopper)limnObjectNix, airMopAlways);

  /* create limnLooks for ellipsoid and for rods */
  lookSoid = limnObjectLookAdd(obj);
  look = obj->look + lookSoid;
  ELL_4V_SET(look->rgba, 1, 1, 1, 1);
  ELL_3V_SET(look->kads, 0.2, 0.8, 0);
  look->spow = 0;
  lookRod = limnObjectLookAdd(obj);
  look = obj->look + lookRod;
  ELL_4V_SET(look->rgba, 0, 0, 0, 1);
  ELL_3V_SET(look->kads, 1, 0, 0);
  look->spow = 0;

  ELL_3M_IDENTITY_SET(matA);
  ELL_3V_SCALE(scale, os, scale);
  ELL_3M_SCALE_SET(matB, scale[0], scale[1], scale[2]);
  ell_3m_post_mul_d(matA, matB);
  if (1 != vs) {
    ELL_3V_NORM(view, view, len);
    if (!len) {
      /* HEY: perhaps do more diplomatic error message here */
      fprintf(stderr, "%s: stupido!\n", me);
      exit(1);
    }
    ELL_3MV_OUTER(matB, view, view);
    ELL_3M_SCALE(matB, vs-1, matB);
    ELL_3M_IDENTITY_SET(matC);
    ELL_3M_ADD2(matB, matC, matB);
    ell_3m_post_mul_d(matA, matB);
  }
  ell_3m_svd_d(uu, sval, vv, matA, AIR_TRUE);

  /*
  fprintf(stderr, "%s: ____________________________________\n", me);
  fprintf(stderr, "%s: mat = \n", me);
  ell_3m_print_d(stderr, matA);
  fprintf(stderr, "%s: uu = \n", me);
  ell_3m_print_d(stderr, uu);
  ELL_3M_TRANSPOSE(matC, uu);
  ELL_3M_MUL(matB, uu, matC);
  fprintf(stderr, "%s: uu * uu^T = \n", me);
  ell_3m_print_d(stderr, matB);
  fprintf(stderr, "%s: sval = %g %g %g\n", me, sval[0], sval[1], sval[2]);
  fprintf(stderr, "%s: vv = \n", me);
  ell_3m_print_d(stderr, vv);
  ELL_3M_MUL(matB, vv, vv);
  fprintf(stderr, "%s: vv * vv^T = \n", me);
  ELL_3M_TRANSPOSE(matC, vv);
  ELL_3M_MUL(matB, vv, matC);
  ell_3m_print_d(stderr, matB);
  ELL_3M_IDENTITY_SET(matA);
  ell_3m_pre_mul_d(matA, uu);
  ELL_3M_SCALE_SET(matB, sval[0], sval[1], sval[2]);
  ell_3m_pre_mul_d(matA, matB);
  ell_3m_pre_mul_d(matA, vv);
  fprintf(stderr, "%s: uu * diag(sval) * vv = \n", me);
  ell_3m_print_d(stderr, matA);
  fprintf(stderr, "%s: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", me);
  */

  ELL_3M_IDENTITY_SET(matA);
  ell_3m_pre_mul_d(matA, uu);
  ELL_3M_SCALE_SET(matB, sval[0], sval[1], sval[2]);
  ell_3m_pre_mul_d(matA, matB);
  ELL_3M_TRANSPOSE(matB, uu);
  ell_3m_pre_mul_d(matA, matB);
  TEN_M2T(ten, matA);

  partIdx = soidDoit(obj, lookSoid,
                     sphere, gamma, res,
                     (AIR_EXISTS(AB[0]) && AIR_EXISTS(AB[1])) ? AB : NULL,
                     ten);

  ELL_4V_SET(q, 1, p[0], p[1], p[2]);
  ELL_4V_NORM(q, q, len);
  ell_q_to_3m_f(mR, q);
  ELL_43M_INSET(matBf, mR);
  limnObjectPartTransform(obj, partIdx, matBf);

  if (rad) {
    partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, (1-scale[0])/2, rad, rad);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, (1+scale[0])/2, 0.0, 0.0);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, (1-scale[0])/2, rad, rad);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, -(1+scale[0])/2, 0.0, 0.0);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, rad, (1-scale[1])/2, rad);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, 0.0, (1+scale[1])/2, 0.0);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, rad, (1-scale[1])/2, rad);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, 0.0, -(1+scale[1])/2, 0.0);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, rad, rad, (1-scale[2])/2);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, 0.0, 0.0, (1+scale[2])/2);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res);
    ELL_4M_IDENTITY_SET(matAf);
    ELL_4M_SCALE_SET(matBf, rad, rad, (1-scale[2])/2);
    ell_4m_post_mul_f(matAf, matBf);
    ELL_4M_TRANSLATE_SET(matBf, 0.0, 0.0, -(1+scale[2])/2);
    ell_4m_post_mul_f(matAf, matBf);
    limnObjectPartTransform(obj, partIdx, matAf);
  }

  file = airFopen(outS, stdout, "w");
  airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

  if (limnObjectWriteOFF(file, obj)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:\n%s\n", me, err);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
Пример #10
0
int
main(int argc, char *argv[]) {
  char *me;
  hestOpt *hopt=NULL;
  airArray *mop;

  char *inS, *outS, *err;
  limnCamera *keycam, *cam;
  limnSplineTypeSpec *quatType, *posType, *distType, *viewType;
  double *time;
  FILE *fin, *fout;
  int N, imgSize[2], trackWhat;
  unsigned int numKeys;

  mop = airMopNew();
  
  me = argv[0];
  hestOptAdd(&hopt, "i", "input", airTypeString, 1, 1, &inS, NULL,
             "keyframe output from camanim.tcl");
  hestOptAdd(&hopt, "n", "# frames", airTypeInt, 1, 1, &N, "128",
             "number of frames in output");
  hestOptAdd(&hopt, "t", "track what", airTypeEnum, 1, 1, &trackWhat, "both",
             "what to track", NULL, limnCameraPathTrack);
  hestOptAdd(&hopt, "q", "spline", airTypeOther, 1, 1, 
             &quatType, "tent", "spline type for quaternions",
             NULL, NULL, limnHestSplineTypeSpec);
  hestOptAdd(&hopt, "p", "spline", airTypeOther, 1, 1, 
             &posType, "tent", "spline type for from/at/up",
             NULL, NULL, limnHestSplineTypeSpec);
  hestOptAdd(&hopt, "d", "spline", airTypeOther, 1, 1, 
             &distType, "tent", "spline type for image plane distances",
             NULL, NULL, limnHestSplineTypeSpec);
  hestOptAdd(&hopt, "v", "spline", airTypeOther, 1, 1, 
             &viewType, "tent", "spline type for image fov and aspect",
             NULL, NULL, limnHestSplineTypeSpec);
  hestOptAdd(&hopt, "o", "output", airTypeString, 1, 1, &outS, NULL,
             "frame info for camanim.tcl");
  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);

  if (!( fin = airFopen(inS, stdin, "r") )) {
    fprintf(stderr, "%s: couldn't open \"%s\" for reading\n", me, inS);
    airMopError(mop); return 1;
  }
  if (!( fout = airFopen(outS, stdout, "w") )) {
    fprintf(stderr, "%s: couldn't open \"%s\" for writing\n", me, outS);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, fin, (airMopper)airFclose, airMopAlways);
  airMopAdd(mop, fout, (airMopper)airFclose, airMopAlways);

  if (_limnReadCamanim(imgSize, &keycam, &time, &numKeys, fin)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble reading keyframe file:\n%s\n", me, err);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, keycam, airFree, airMopAlways);
  airMopAdd(mop, time, airFree, airMopAlways);
  cam = (limnCamera *)calloc(N, sizeof(limnCamera));
  airMopAdd(mop, cam, airFree, airMopAlways);
  if (limnCameraPathMake(cam, N, keycam, time, numKeys, trackWhat,
                         quatType, posType, distType, viewType)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble making camera path:\n%s\n", me, err);
    airMopError(mop); return 1;
  }
  if (_limnWriteCamanim(fout, imgSize, cam, N)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble writing frame file:\n%s\n", me, err);
    airMopError(mop); return 1;
  }
  
  airMopOkay(mop);
  return 0;
}
Пример #11
0
int
main(int argc, char *argv[]) {
  char *me, *err, *outS;
  hestOpt *hopt=NULL;
  airArray *mop;

  int numGrth, numDtdi, numGrgr, numDtgr, numNrrd, ni;
  plotPS pps;
  plotParm pparm;
  Nrrd **_ndata, **ndata;

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

  hestOptAdd(&hopt, "i", "data", airTypeOther, 1, -1, &_ndata, NULL,
             "input nrrd containing data to plot",
             &numNrrd, NULL, nrrdHestNrrd);
  hestOptAdd(&hopt, "dbox", "minX minY maxX maxY", airTypeDouble,
             4, 4, pparm.dbox, NULL,
             "bounding box, in data space");
  
  hestOptAdd(&hopt, "bbox", "minX minY maxX maxY", airTypeDouble,
             4, 4, pps.bbox, NULL,
             "bounding box, in graph space");
  hestOptAdd(&hopt, "psc", "PS scale", airTypeDouble, 1, 1, &(pps.psc), "300",
             "scaling from graph space to PostScript points");
  hestOptAdd(&hopt, "nobg", NULL, airTypeInt, 0, 0, &(pps.nobg), NULL,
             "don't fill with background color");
  hestOptAdd(&hopt, "bg", "background", airTypeDouble, 3, 3,
             &(pps.bgColor), "1 1 1",
             "background RGB color; each component in range [0.0,1.0]");
  
  hestOptAdd(&hopt, "grth", "graph thickness", airTypeDouble,
             1, -1, &(pparm.graphThick), "0.01",
             "thickness of line for graph, or \"0\" for no graph line", 
             &numGrth);
  hestOptAdd(&hopt, "grgr", "graph gray", airTypeDouble,
             1, -1, &(pparm.graphGray), "0",
             "grayscale to use for graph", &numGrgr);
  hestOptAdd(&hopt, "dtdi", "dot diameter", airTypeDouble,
             1, -1, &(pparm.dotDiameter), "0.1",
             "radius of dot drawn at data points, or \"0\" for no dots",
             &numDtdi);
  hestOptAdd(&hopt, "dtgr", "dot gray", airTypeDouble,
             1, -1, &(pparm.dotGray), "0",
             "grayscale to use for dots", &numDtgr);
  hestOptAdd(&hopt, "dtid", "dot inner diam frac", airTypeDouble,
             1, 1, &(pparm.dotInnerDiameterFraction), "0.0",
             "fractional radius of white dot drawn within dot");

  hestOptAdd(&hopt, "tihz", "pos", airTypeDouble,
             0, -1, &(pparm.horzTick), "",
             "locations for tickmarks on horizontal axis",
             &(pparm.numHorzTick));
  hestOptAdd(&hopt, "tivt", "pos", airTypeDouble,
             0, -1, &(pparm.vertTick), "",
             "locations for tickmarks on vertical axis",
             &(pparm.numVertTick));
  hestOptAdd(&hopt, "tiho", "offset", airTypeDouble,
             1, 1, &(pparm.horzTickLabelOffset), "0",
             "horizontal tick label offset");
  hestOptAdd(&hopt, "tivo", "offset", airTypeDouble,
             1, 1, &(pparm.vertTickLabelOffset), "0",
             "vertical tick label offset");
  hestOptAdd(&hopt, "tils", "size", airTypeDouble,
             1, 1, &(pparm.tickLabelSize), "0",
             "font size for labels on tick marks, or \"0\" for no labels");
  hestOptAdd(&hopt, "tith", "tick thickness", airTypeDouble,
             1, 1, &(pparm.tickThick), "0.01",
             "thickness of lines for tick marks");
  hestOptAdd(&hopt, "tiln", "tick length", airTypeDouble,
             1, 1, &(pparm.tickLength), "0.08",
             "length of lines for tick marks");

  hestOptAdd(&hopt, "axth", "axis thickness", airTypeDouble,
             1, 1, &(pparm.axisThick), "0.01",
             "thickness of lines for axes");
  hestOptAdd(&hopt, "axor", "axis origin", airTypeDouble,
             2, 2, &(pparm.axisOrig), "0 0",
             "origin of lines for axes, in data space");
  hestOptAdd(&hopt, "axhl", "horiz axis label", airTypeString,
             1, 1, &(pparm.axisHorzLabel), "",
             "label on horizontal axis");
  hestOptAdd(&hopt, "axvl", "vert axis label", airTypeString,
             1, 1, &(pparm.axisVertLabel), "",
             "label on vertical axis");

  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);

  if (!( numGrth == numDtdi 
         && numDtdi == numGrgr
         && numGrgr == numDtgr )) {
    fprintf(stderr, "%s: number of arguments given to grth (%d), dtdi (%d), "
            "grgr (%d), dtgr (%d) not all equal\n", me,
            numGrth, numDtdi, numGrgr, numDtgr);
    airMopError(mop); return 1;
  }
  if (!( numNrrd == numGrth )) {
    fprintf(stderr, "%s: number of nrrds (%d) != number graph options (%d)\n",
            me, numNrrd, numGrth);
    airMopError(mop); return 1;
  }

  /* check nrrds */
  for (ni=0; ni<numNrrd; ni++) {
    if (!( (1 == _ndata[ni]->dim || 2 == _ndata[ni]->dim) 
           && nrrdTypeBlock != _ndata[ni]->type )) {
      fprintf(stderr, "%s: input nrrd must be 1-D or 2-D array of scalars",
              me);
      airMopError(mop); return 1;
    }
  }
  ndata = (Nrrd**)calloc(numNrrd, sizeof(Nrrd *));
  airMopAdd(mop, ndata, airFree, airMopAlways);
  for (ni=0; ni<numNrrd; ni++) {
    ndata[ni] = nrrdNew();
    airMopAdd(mop, ndata[ni], (airMopper)nrrdNuke, airMopAlways);
    if (nrrdConvert(ndata[ni], _ndata[ni], nrrdTypeDouble)) {
      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
      fprintf(stderr, "%s: couldn't convert input %d to %s:\n%s\n",
              me, ni, airEnumStr(nrrdType, nrrdTypeDouble), err);
      airMopError(mop); return 1;
    }
    if (1 == ndata[ni]->dim) {
      if (nrrdAxesInsert(ndata[ni], ndata[ni], 0)) {
        airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
        fprintf(stderr, "%s: couldn't insert axis 0 on nrrd %d:\n%s\n",
                me, ni, err);
        airMopError(mop); return 1;
      }
    }
    /* currently assuming node centering */
    if (!AIR_EXISTS(ndata[ni]->axis[1].min)) {
      ndata[ni]->axis[1].min = 0;
    }
    if (!AIR_EXISTS(ndata[ni]->axis[1].max)) {
      ndata[ni]->axis[1].max = ndata[ni]->axis[1].size-1;
    }
  }

  if (!(pps.file = airFopen(outS, stdout, "wb"))) {
    fprintf(stderr, "%s: couldn't open output file\n", me);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, pps.file, (airMopper)airFclose, airMopAlways);
  
  plotPreamble(&pps, &pparm);
  plotAxes(&pps, &pparm, ndata[0]);
  for (ni=0; ni<numNrrd; ni++) {
    plotGraph(&pps, &pparm, ndata, ni);
    plotDots(&pps, &pparm, ndata, ni);
  }
  plotEpilog(&pps, &pparm);

  airMopOkay(mop);
  return 0;
}
Пример #12
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;
}
Пример #13
0
int
tkwbReadSlides(tkwbSlide ***slideP, char *filename, airArray *pmop) {
    char me[]="tkwbReadSlides", err[BIFF_STRLEN];
    FILE *file;
    airArray *mop, *slideArr;
    tkwbSlide **slide = NULL;
    char *title, *image, *text, stop[AIR_STRLEN_HUGE], line[AIR_STRLEN_HUGE];
    int slideIdx=0, hitEOF, notReally;
    unsigned int len;
    _tkwbU uu;

    mop = airMopNew();
    if (!( file = airFopen(filename, stdin, "rb") )) {
        sprintf(err, "%s: couldn't open %s: %s", me, filename, strerror(errno));
        biffAdd(TKWB, err);
        airMopError(mop);
        return 1;
    }
    airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

    len = airOneLine(file, stop, AIR_STRLEN_HUGE);
    if (!( len > 1 )) {
        sprintf(err, "%s: didn't get a stop delimiter from %s", me, filename);
        biffAdd(TKWB, err);
        airMopError(mop);
        return 1;
    }

    uu.ps = &slide;
    slideArr = airArrayNew(uu.v, NULL,
                           sizeof(tkwbSlide*), tkwbArrayIncr);
    airMopAdd(mop, slideArr, (airMopper)airArrayNix, airMopAlways);
    hitEOF = notReally = AIR_FALSE;
    while (!hitEOF) {
        slideIdx = airArrayLenIncr(slideArr, 1); /* HEY error checking */
        len = airOneLine(file, line, AIR_STRLEN_HUGE);
        if (!len) {
            /* got EOF after a division marker, that's okay */
            notReally = AIR_TRUE;
            break;
        }
        title = airStrdup(line);
        len = airOneLine(file, line, AIR_STRLEN_HUGE);
        if (!len) {
            break;
        }
        image = airStrdup(line);
        if (tkwbReadFileToString(&text, &hitEOF, file, stop)) {
            sprintf(err, "%s: couldn't read in slide %d", me, slideIdx);
            biffAdd(TKWB, err);
            airMopError(mop);
            return 1;
        }
        slide[slideIdx] = tkwbSlideNew(title, image, text);
        airMopAdd(pmop, slide[slideIdx], (airMopper)tkwbSlideNix, airMopAlways);
    }
    if (!hitEOF && !notReally) {
        sprintf(err, "%s: got incomplete slide info for slide %d\n", me, slideIdx);
        biffAdd(TKWB, err);
        airMopError(mop);
        return 1;
    }
    if (!notReally) {
        slideIdx = airArrayLenIncr(slideArr, 1); /* HEY error checking */
    }
    slide[slideIdx] = NULL;

    *slideP = slide;
    airMopOkay(mop);
    return 0;
}
Пример #14
0
int
main(int argc, const char *argv[]) {
  const char *me;
  char *err, *outS;
  float p[3], q[4], mR[9], eval[3]={0,0,0}, scale[3], len, sh, cl, cp, qA, qB;
  float matA[16], matB[16], os, rad, AB[2];
  hestOpt *hopt=NULL;
  airArray *mop;
  limnObject *obj;
  limnLook *look; int lookRod, lookSoid;
  int partIdx=-1; /* sssh */
  int res, axis, sphere;
  FILE *file;


  me = argv[0];
  hestOptAdd(&hopt, "sc", "scalings", airTypeFloat, 3, 3, scale, "1 1 1",
             "axis-aligned scaling to do on ellipsoid");
  hestOptAdd(&hopt, "AB", "A, B exponents", airTypeFloat, 2, 2, AB, "nan nan",
             "Directly set the A, B parameters to the superquadric surface, "
             "over-riding the default behavior of determining them from the "
             "scalings \"-sc\" as superquadric tensor glyphs");
  hestOptAdd(&hopt, "os", "over-all scaling", airTypeFloat, 1, 1, &os, "1",
             "over-all scaling (multiplied by scalings)");
  hestOptAdd(&hopt, "sh", "superquad sharpness", airTypeFloat, 1, 1, &sh, "0",
             "how much to sharpen edges as a "
             "function of differences between eigenvalues");
  hestOptAdd(&hopt, "sphere", NULL, airTypeInt, 0, 0, &sphere, NULL,
             "use a sphere instead of a superquadric");
  hestOptAdd(&hopt, "p", "x y z", airTypeFloat, 3, 3, p, "0 0 0",
             "location in quaternion quotient space");
  hestOptAdd(&hopt, "r", "radius", airTypeFloat, 1, 1, &rad, "0.015",
             "black axis cylinder radius (or 0.0 to not drawn these)");
  hestOptAdd(&hopt, "res", "resolution", airTypeInt, 1, 1, &res, "25",
             "tesselation resolution for both glyph and axis cylinders");
  hestOptAdd(&hopt, "o", "output OFF", airTypeString, 1, 1, &outS, "out.off",
             "output file to save OFF into");
  hestParseOrDie(hopt, argc-1, argv+1, NULL,
                 me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  mop = airMopNew();
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  obj = limnObjectNew(100, AIR_FALSE);
  airMopAdd(mop, obj, (airMopper)limnObjectNix, airMopAlways);

  /* create limnLooks for ellipsoid and for rods */
  lookSoid = limnObjectLookAdd(obj);
  look = obj->look + lookSoid;
  ELL_4V_SET(look->rgba, 1, 1, 1, 1);
  ELL_3V_SET(look->kads, 0.2, 0.8, 0);
  look->spow = 0;
  lookRod = limnObjectLookAdd(obj);
  look = obj->look + lookRod;
  ELL_4V_SET(look->rgba, 0, 0, 0, 1);
  ELL_3V_SET(look->kads, 1, 0, 0);
  look->spow = 0;

  ELL_4V_SET(q, 1, p[0], p[1], p[2]);
  ELL_4V_NORM(q, q, len);
  ell_q_to_3m_f(mR, q);

  if (AIR_EXISTS(AB[0]) && AIR_EXISTS(AB[1])) {
    qA = AB[0];
    qB = AB[1];
    axis = 2;
  } else {
    ELL_3V_SCALE(scale, os, scale);
    ELL_3V_COPY(eval, scale);
    ELL_SORT3(eval[0], eval[1], eval[2], cl);
    cl = (eval[0] - eval[1])/(eval[0] + eval[1] + eval[2]);
    cp = 2*(eval[1] - eval[2])/(eval[0] + eval[1] + eval[2]);
    if (cl > cp) {
      axis = ELL_MAX3_IDX(scale[0], scale[1], scale[2]);
      qA = pow(1-cp, sh);
      qB = pow(1-cl, sh);
    } else {
      axis = ELL_MIN3_IDX(scale[0], scale[1], scale[2]);
      qA = pow(1-cl, sh);
      qB = pow(1-cp, sh);
    }
    /*
    fprintf(stderr, "eval = %g %g %g -> cl=%g %s cp=%g -> axis = %d\n",
            eval[0], eval[1], eval[2], cl, cl > cp ? ">" : "<", cp, axis);
    */
  }
  if (sphere) {
    partIdx = limnObjectPolarSphereAdd(obj, lookSoid,
                                       0, 2*res, res);
  } else {
    partIdx = limnObjectPolarSuperquadAdd(obj, lookSoid,
                                          axis, qA, qB, 2*res, res);
  }
  ELL_4M_IDENTITY_SET(matA);
  ELL_4M_SCALE_SET(matB, scale[0], scale[1], scale[2]);
  ell_4m_post_mul_f(matA, matB);
  ELL_43M_INSET(matB, mR);
  ell_4m_post_mul_f(matA, matB);
  limnObjectPartTransform(obj, partIdx, matA);

  if (rad) {
    partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, (1-eval[0])/2, rad, rad);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, (1+eval[0])/2, 0.0, 0.0);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, (1-eval[0])/2, rad, rad);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, -(1+eval[0])/2, 0.0, 0.0);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, rad, (1-eval[1])/2, rad);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 0.0, (1+eval[1])/2, 0.0);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, rad, (1-eval[1])/2, rad);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 0.0, -(1+eval[1])/2, 0.0);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, rad, rad, (1-eval[2])/2);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, (1+eval[2])/2);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);

    partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res);
    ELL_4M_IDENTITY_SET(matA);
    ELL_4M_SCALE_SET(matB, rad, rad, (1-eval[2])/2);
    ell_4m_post_mul_f(matA, matB);
    ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, -(1+eval[2])/2);
    ell_4m_post_mul_f(matA, matB);
    limnObjectPartTransform(obj, partIdx, matA);
  }

  file = airFopen(outS, stdout, "w");
  airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

  if (limnObjectWriteOFF(file, obj)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:\n%s\n", me, err);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
Пример #15
0
int
main(int argc, const char *argv[]) {
  const char *me;
  char *err, *outS;
  hestOpt *hopt=NULL;
  airArray *mop;

  limnPolyData *pld, *pldSub;
  gageContext *gctx=NULL;
  gagePerVolume *pvl;
  Nrrd *nin, *nmeas;
  double kparm[3], strength, scaling[3];
  seekContext *sctx;
  FILE *file;
  unsigned int ncc;
  size_t samples[3];
  gageKind *kind;
  char *itemGradS; /* , *itemEvalS[2], *itemEvecS[2]; */
  int itemGrad; /* , itemEval[2], itemEvec[2]; */
  int E;

  me = argv[0];
  hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL,
             "input volume to analyze",
             NULL, NULL, nrrdHestNrrd);
  hestOptAdd(&hopt, "k", "kind", airTypeOther, 1, 1, &kind, NULL,
             "\"kind\" of volume (\"scalar\", \"vector\", \"tensor\")",
             NULL, NULL, &probeKindHestCB);
  hestOptAdd(&hopt, "s", "strength", airTypeDouble, 1, 1, &strength, "0.01",
             "strength");
  hestOptAdd(&hopt, "gi", "grad item", airTypeString, 1, 1, &itemGradS, NULL,
             "item for gradient vector");
  hestOptAdd(&hopt, "c", "scaling", airTypeDouble, 3, 3, scaling, "1 1 1",
             "amount by which to up/down-sample on each spatial axis");
  hestOptAdd(&hopt, "n", "# CC", airTypeUInt, 1, 1, &ncc, "0",
             "if non-zero, number of CC to save");
  hestOptAdd(&hopt, "o", "output LMPD", airTypeString, 1, 1, &outS, "out.lmpd",
             "output file to save LMPD into");
  hestParseOrDie(hopt, argc-1, argv+1, NULL,
                 me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  mop = airMopNew();
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  itemGrad = airEnumVal(kind->enm, itemGradS);

  pld = limnPolyDataNew();
  airMopAdd(mop, pld, (airMopper)limnPolyDataNix, airMopAlways);
  pldSub = limnPolyDataNew();
  airMopAdd(mop, pldSub, (airMopper)limnPolyDataNix, airMopAlways);

  file = airFopen(outS, stdout, "w");
  airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

  sctx = seekContextNew();
  airMopAdd(mop, sctx, (airMopper)seekContextNix, airMopAlways);

  gctx = gageContextNew();
  airMopAdd(mop, gctx, (airMopper)gageContextNix, airMopAlways);
  ELL_3V_SET(kparm, 1, 1.0, 0.0);
  if (!(pvl = gagePerVolumeNew(gctx, nin, kind))
      || gagePerVolumeAttach(gctx, pvl)
      || gageKernelSet(gctx, gageKernel00, nrrdKernelBCCubic, kparm)
      || gageKernelSet(gctx, gageKernel11, nrrdKernelBCCubicD, kparm)
      || gageKernelSet(gctx, gageKernel22, nrrdKernelBCCubicDD, kparm)
      || gageQueryItemOn(gctx, pvl, itemGrad)
      || gageQueryItemOn(gctx, pvl, gageSclHessEval)
      || gageQueryItemOn(gctx, pvl, gageSclHessEval2)
      || gageQueryItemOn(gctx, pvl, gageSclHessEvec)
      || gageQueryItemOn(gctx, pvl, gageSclHessEvec2)
      || gageUpdate(gctx)) {
    airMopAdd(mop, err = biffGetDone(GAGE), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:\n%s\n", me, err);
    airMopError(mop); return 1;
  }

  seekVerboseSet(sctx, 10);

  E = 0;
  if (!E) E |= seekDataSet(sctx, NULL, gctx, 0);
  ELL_3V_SET(samples,
             scaling[0]*nin->axis[kind->baseDim + 0].size,
             scaling[1]*nin->axis[kind->baseDim + 1].size,
             scaling[2]*nin->axis[kind->baseDim + 2].size);
  if (!E) E |= seekSamplesSet(sctx, samples);
  if (!E) E |= seekItemGradientSet(sctx, itemGrad);
  if (!E) E |= seekItemEigensystemSet(sctx, gageSclHessEval,
                                      gageSclHessEvec);
  if (!E) E |= seekItemNormalSet(sctx, gageSclHessEvec2);
  if (!E) E |= seekStrengthUseSet(sctx, AIR_TRUE);
  if (!E) E |= seekStrengthSet(sctx, -1, strength);
  if (!E) E |= seekItemStrengthSet(sctx, gageSclHessEval2);
  if (!E) E |= seekNormalsFindSet(sctx, AIR_TRUE);
  if (!E) E |= seekTypeSet(sctx, seekTypeRidgeSurface);
  if (!E) E |= seekUpdate(sctx);
  if (!E) E |= seekExtract(sctx, pld);
  if (E) {
    airMopAdd(mop, err = biffGetDone(SEEK), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:\n%s\n", me, err);
    airMopError(mop); return 1;
  }
  fprintf(stderr, "%s: extraction time = %g\n", me, sctx->time);

  nmeas = nrrdNew();
  airMopAdd(mop, nmeas, (airMopper)nrrdNuke, airMopAlways);
  if (limnPolyDataVertexWindingFix(pld, AIR_TRUE)
      || limnPolyDataVertexWindingFlip(pld)
      || limnPolyDataVertexNormals(pld)
      || limnPolyDataCCFind(pld)
      || limnPolyDataPrimitiveArea(nmeas, pld)
      || limnPolyDataPrimitiveSort(pld, nmeas)) {
    err = biffGetDone(LIMN);
    fprintf(stderr, "%s: trouble sorting:\n%s", me, err);
    free(err);
  }

  if (ncc > 1) {
    double *meas;
    unsigned int ccIdx;
    nrrdSave("meas.nrrd", nmeas, NULL);
    ncc = AIR_MIN(ncc, nmeas->axis[0].size);
    meas = AIR_CAST(double *, nmeas->data);
    for (ccIdx=ncc; ccIdx<nmeas->axis[0].size; ccIdx++) {
      meas[ccIdx] = 0.0;
    }
    if (!E) E |= limnPolyDataPrimitiveSelect(pldSub, pld, nmeas);
    if (!E) E |= limnPolyDataWriteLMPD(file, pldSub);
  } else {
Пример #16
0
int
main(int argc, char *argv[]) {
    char *me, *outS;
    hestOpt *hopt;
    hestParm *hparm;
    airArray *mop;

    int fidx, aidx, num, frames;
    double psc, width[2], arrowWidth, lineWidth, angle, seglen,
           x0, y0, x1, y1, cc, ss;
    wheelPS wps;
    char filename[AIR_STRLEN_MED];

    me = argv[0];
    mop = airMopNew();
    hparm = hestParmNew();
    hparm->elideMultipleNonExistFloatDefault = AIR_TRUE;
    hopt = NULL;
    airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);
    hestOptAdd(&hopt, "w", "arrowWidth lineWidth", airTypeDouble, 2, 2, width,
               "1.0 0.2", "widths");
    hestOptAdd(&hopt, "n", "number", airTypeInt, 1, 1, &num, "10",
               "number of arrows");
    hestOptAdd(&hopt, "f", "frames", airTypeInt, 1, 1, &frames, "10",
               "number of frames");
    hestOptAdd(&hopt, "psc", "scale", airTypeDouble, 1, 1, &psc, "200",
               "scaling from world space to PostScript points");
    hestOptAdd(&hopt, "o", "prefix", airTypeString, 1, 1, &outS, NULL,
               "prefix of file names");
    hestParseOrDie(hopt, argc-1, argv+1, hparm,
                   me, interInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE);
    airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
    airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

    for (fidx=0; fidx<frames; fidx++) {
        sprintf(filename, "%s%03d.eps", outS, fidx);
        if (!(wps.file = airFopen(filename, stdout, "wb"))) {
            fprintf(stderr, "%s: couldn't open output file\n", me);
            airMopError(mop);
            return 1;
        }

        lineWidth = width[0];
        arrowWidth = width[1];
        wps.psc = psc;
        ELL_4V_SET(wps.bbox, -0.45, -0.85, 1.1, 0.85);
        wheelPreamble(&wps);

        fprintf(wps.file, "0 setlinecap\n");

        wheelGray(&wps, 0.4);
        wheelWidth(&wps, lineWidth);

        x0 = 0;
        y0 = 0;
        seglen = 1.0/num;
        angle = AIR_AFFINE(0, fidx, frames, 0, 2*AIR_PI);
        for (aidx=1; aidx<=num; aidx++) {
            cc = cos(angle*aidx)*seglen;
            ss = sin(angle*aidx)*seglen;
            x1 = x0 + 0.90*cc;
            y1 = y0 + 0.90*ss;
            wheelArrow(&wps, x0, y0, x1, y1, arrowWidth, arrowWidth*0.4);
            x0 += cc;
            y0 += ss;
        }

        wheelGray(&wps, 0.0);
        wheelArrow(&wps, 0, 0, x0, y0, arrowWidth, arrowWidth*0.4);

        wheelEpilog(&wps);
        airFclose(wps.file);
    }

    airMopOkay(mop);
    exit(0);
}
int
tend_ellipseMain(int argc, char **argv, char *me, hestParm *hparm) {
  int pret;
  hestOpt *hopt = NULL;
  char *perr;
  airArray *mop;

  Nrrd *nten, *npos, *nstn;
  char *outS;
  float gscale, dotRad, lineWidth, cthresh, min[2], max[2];
  FILE *fout;
  int invert;

  mop = airMopNew();

  hestOptAdd(&hopt, "ctr", "conf thresh", airTypeFloat, 1, 1, &cthresh, "0.5",
             "Glyphs will be drawn only for tensors with confidence "
             "values greater than this threshold");
  hestOptAdd(&hopt, "gsc", "scale", airTypeFloat, 1, 1, &gscale, "1",
             "over-all glyph size");
  hestOptAdd(&hopt, "dot", "radius", airTypeFloat, 1, 1, &dotRad, "0.0",
             "radius of little dot to put in middle of ellipse, or \"0\" "
             "for no such dot");
  hestOptAdd(&hopt, "wid", "width", airTypeFloat, 1, 1, &lineWidth, "0.0",
             "with of lines for tractlets");
  hestOptAdd(&hopt, "inv", NULL, airTypeInt, 0, 0, &invert, NULL,
             "use white ellipses on black background, instead of reverse");
  hestOptAdd(&hopt, "min", "minX minY", airTypeFloat, 2, 2, min, "-1 -1",
             "when using \"-p\", minimum corner");
  hestOptAdd(&hopt, "max", "maxX maxY", airTypeFloat, 2, 2, max, "1 1",
             "when using \"-p\", maximum corner");

  /* input/output */
  hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nten, "-",
             "image of 2D tensors", NULL, NULL, nrrdHestNrrd);
  hestOptAdd(&hopt, "p", "pos array", airTypeOther, 1, 1, &npos, "",
             "Instead of being on a grid, tensors are at arbitrary locations, "
             "as defined by this 2-by-N array of floats", NULL, NULL,
             nrrdHestNrrd);
  hestOptAdd(&hopt, "s", "stn array", airTypeOther, 1, 1, &nstn, "",
             "Locations given by \"-p\" have this connectivity", NULL, NULL,
             nrrdHestNrrd);
  hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",
             "output PostScript file");

  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  USAGE(_tend_ellipseInfoL);
  PARSE();
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  if (npos) {
    if (!( 2 == nten->dim && 4 == nten->axis[0].size
           && 2 == npos->dim && 2 == npos->axis[0].size
           && nten->axis[1].size == npos->axis[1].size )) {
      fprintf(stderr, "%s: didn't get matching lists of tensors and pos's\n",
              me);
      airMopError(mop); return 1;
    }
    if (!( nrrdTypeFloat == npos->type )) {
      fprintf(stderr, "%s: didn't get float type positions\n", me);
      airMopError(mop); return 1;
    }
  } else {
    if (!(3 == nten->dim && 4 == nten->axis[0].size)) {
      fprintf(stderr, "%s: didn't get a 3-D 4-by-X-by-Y 2D tensor array\n",
              me);
      airMopError(mop); return 1;
    }
  }
  if (!( nrrdTypeFloat == nten->type )) {
    fprintf(stderr, "%s: didn't get float type tensors\n", me);
    airMopError(mop); return 1;
  }
  if (nstn) {
    if (!( nrrdTypeUInt == nstn->type 
           && 2 == nstn->dim
           && 3 == nstn->axis[0].size )) {
      fprintf(stderr, "%s: connectivity isn't 2-D 3-by-N array of %ss\n",
              me, airEnumStr(nrrdType, nrrdTypeInt));
      airMopError(mop); return 1;
    }
  }
  if (!(fout = airFopen(outS, stdout, "wb"))) {
    fprintf(stderr, "%s: couldn't open \"%s\" for writing\n", me, outS);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, fout, (airMopper)airFclose, airMopAlways);

  tend_ellipseDoit(fout, nten, npos, nstn, min, max, 
                   gscale, dotRad, lineWidth, cthresh, invert);

  airMopOkay(mop);
  return 0;
}
Пример #18
0
void
undosConvert(char *me, char *name, int reverse, int mac,
             int quiet, int noAction) {
  airArray *mop;
  FILE *fin, *fout;
  char *data=NULL;
  airArray *dataArr;
  unsigned int ci;
  int car, numBad, willConvert;
  _undosU uu;

  mop = airMopNew();
  if (!airStrlen(name)) {
    fprintf(stderr, "%s: empty filename\n", me);
    airMopError(mop); return;
  }

  /* -------------------------------------------------------- */
  /* open input file  */
  fin = airFopen(name, stdin, "rb");
  if (!fin) {
    if (!quiet) {
      fprintf(stderr, "%s: couldn't open \"%s\" for reading: \"%s\"\n", 
              me, name, strerror(errno));
    }
    airMopError(mop); return;
  }
  airMopAdd(mop, fin, (airMopper)airFclose, airMopOnError);

  /* -------------------------------------------------------- */
  /* create buffer */
  uu.c = &data;
  dataArr = airArrayNew(uu.v, NULL, sizeof(char), AIR_STRLEN_HUGE);
  if (!dataArr) {
    if (!quiet) {
      fprintf(stderr, "%s: internal allocation error #1\n", me);
    }
    airMopError(mop); return;
  }
  airMopAdd(mop, dataArr, (airMopper)airArrayNuke, airMopAlways);

  /* -------------------------------------------------------- */
  /* read input file, testing for binary-ness along the way */
  numBad = 0;
  car = getc(fin);
  if (EOF == car) {
    if (!quiet) {
      fprintf(stderr, "%s: \"%s\" is empty, skipping ...\n", me, name);
    }
    airMopError(mop); return;
  }
  do {
    ci = airArrayLenIncr(dataArr, 1);
    if (!dataArr->data) {
      if (!quiet) {
        fprintf(stderr, "%s: internal allocation error #2\n", me);
      }
      airMopError(mop); return;
    }
    data[ci] = car;
    numBad += !(isprint(data[ci]) || isspace(data[ci]));
    car = getc(fin);
  } while (EOF != car && BAD_PERC > 100.0*numBad/dataArr->len);
  if (EOF != car) {
    if (!quiet) {
      fprintf(stderr, "%s: more than %g%% of \"%s\" is non-printing, "
              "skipping ...\n", me, BAD_PERC, name);
    }
    airMopError(mop); return;    
  }
  fin = airFclose(fin);

  /* -------------------------------------------------------- */
  /* see if we really need to do anything */
  willConvert = AIR_FALSE;
  if (!strcmp("-", name)) {
    willConvert = AIR_TRUE;
  } else if (reverse) {
    for (ci=0; ci<dataArr->len; ci++) {
      if (mac) {
        if (CR == data[ci]) {
          willConvert = AIR_TRUE;
          break;
        }
      } else {
        if (CR == data[ci] && (ci && LF != data[ci-1])) {
          willConvert = AIR_TRUE;
          break;
        }
      }
    }
  } else {
    for (ci=0; ci<dataArr->len; ci++) {
      if (mac) {
        if (LF == data[ci]) {
          willConvert = AIR_TRUE;
          break;
        }
      } else {
        if (LF == data[ci] && (ci+1<dataArr->len && CR == data[ci+1])) {
          willConvert = AIR_TRUE;
          break;
        }
      }
    }
  }
  if (!willConvert) {
    /* no, we don't need to do anything; quietly quit */
    airMopOkay(mop);
    return;
  } else {
    if (!quiet) {
      fprintf(stderr, "%s: %s \"%s\" %s %s ... \n", me, 
              noAction ? "would convert" : "converting",
              name,
              reverse ? "to" : "from",
              mac ? "MAC" : "DOS");
    }
  }
  if (noAction) {
    /* just joking, we won't actually write anything.
       (yes, even if input was stdin) */
    airMopOkay(mop);
    return;
  }

  /* -------------------------------------------------------- */
  /* open output file */
  fout = airFopen(name, stdout, "wb");
  if (!fout) {
    if (!quiet) {
      fprintf(stderr, "%s: couldn't open \"%s\" for writing: \"%s\"\n", 
              me, name, strerror(errno));
    }
    airMopError(mop); return;
  }
  airMopAdd(mop, fout, (airMopper)airFclose, airMopOnError);

  /* -------------------------------------------------------- */
  /* write output file */
  car = 'a';
  if (reverse) {
    for (ci=0; ci<dataArr->len; ci++) {
      if ((mac && CR == data[ci])
          || (CR == data[ci] && (ci && LF != data[ci-1]))) {
        car = putc(LF, fout);
        if (!mac && EOF != car) {
          car = putc(CR, fout);
        }
      } else {
        car = putc(data[ci], fout);
      }
    }
  } else {
    for (ci=0; EOF != car && ci<dataArr->len; ci++) {
      if ((mac && LF == data[ci])
          || (LF == data[ci] && (ci+1<dataArr->len && CR == data[ci+1]))) {
        car = putc(CR, fout);
        ci += !mac;
      } else {
        car = putc(data[ci], fout);
      }
    }
  }
  if (EOF == car) {
    if (!quiet) {
      fprintf(stderr, "%s: ERROR writing \"%s\" possible data loss !!! "
              "(sorry)\n", me, name);
    }
  }
  fout = airFclose(fout);

  airMopOkay(mop);
  return;
}
Пример #19
0
int
main(int argc, char *argv[]) {
    char *me;
    hestOpt *hopt=NULL;
    airArray *mop;

    NrrdIoState *nio;
    FILE *file;
    char *outS;
    Nrrd *nin;
    float width, scale, hack, minX, maxX, minY, maxY;
    int gray, sx, sy, labels;

    mop = airMopNew();
    me = argv[0];
    hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL,
               "input image.  Must be SQUARE 8-bit RGB or gray",
               NULL, NULL, nrrdHestNrrd);
    hestOptAdd(&hopt, "w", "width", airTypeFloat, 1, 1, &width, "0.0",
               "border width to put around triangle, in pixels, "
               "or \"0\" to not have any border");
    hestOptAdd(&hopt, "labels", NULL, airTypeInt, 0, 0, &labels, NULL,
               "put little labels on things; fix with psfrag in LaTeX");
    hestOptAdd(&hopt, "o", "output EPS", airTypeString, 1, 1, &outS, NULL,
               "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);

    if (!( 2 == nin->dim || 3 == nin->dim )) {
        fprintf(stderr, "%s: input nrrd must be 2-D or 3-D (not %d-D)\n", me,
                nin->dim);
        airMopError(mop);
        return 1;
    }
    if (!( nrrdTypeUChar == nin->type )) {
        fprintf(stderr, "%s: input nrrd must be type %s (not %s)\n", me,
                airEnumStr(nrrdType, nrrdTypeUChar),
                airEnumStr(nrrdType, nin->type));
        airMopError(mop);
        return 1;
    }
    sx = (2 == nin->dim ? nin->axis[0].size : nin->axis[1].size);
    sy = (2 == nin->dim ? nin->axis[1].size : nin->axis[2].size);
    gray = 2 == nin->dim || 1 == nin->axis[0].size;
    if (!( sx == sy )) {
        fprintf(stderr, "%s: image must be square (not %d x %d)\n", me, sx, sy);
        airMopError(mop);
        return 1;
    }

    if (!( file = airFopen(outS, stdout, "wb") )) {
        fprintf(stderr, "%s: couldn't open \"%s\" for writing", me, outS);
        airMopError(mop);
        return 1;
    }
    airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);
    nio = nrrdIoStateNew();
    airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways);

    hack = sqrt(3)/2;
    /* sorry, copied from nrrd/formatEPS.c */
    minX = 0.5;
    maxX = 8.0;
    minY = 5.50 - 7.5*hack*sy/sx/2;
    maxY = 5.50 + 7.5*hack*sy/sx/2;
    scale = 7.5/sx;
    minX *= 72;
    minY *= 72;
    maxX *= 72;
    maxY *= 72;
    scale *= 72;
    fprintf(file, "%%!PS-Adobe-3.0 EPSF-3.0\n");
    fprintf(file, "%%%%Creator: hairy pathetic monster\n");
    fprintf(file, "%%%%Title: raving lunatic\n");
    fprintf(file, "%%%%Pages: 1\n");
    fprintf(file, "%%%%BoundingBox: %d %d %d %d\n",
            (int)floor(minX), (int)floor(minY),
            (int)ceil(maxX), (int)ceil(maxY));
    fprintf(file, "%%%%HiResBoundingBox: %g %g %g %g\n",
            minX, minY, maxX, maxY);
    fprintf(file, "%%%%EndComments\n");
    fprintf(file, "%%%%BeginProlog\n");
    fprintf(file, "%% linestr creates an empty string to hold "
            "one scanline\n");
    fprintf(file, "/linestr %d string def\n", sx*(gray ? 1 : 3));
    fprintf(file, "%%%%EndProlog\n");
    fprintf(file, "%%%%Page: 1 1\n");
    fprintf(file, "gsave\n");

    fprintf(file, "%g %g moveto\n", minX, minY);
    fprintf(file, "%g %g lineto\n", maxX, minY);
    fprintf(file, "%g %g lineto\n",
            (minX + maxX)/2, minY + hack*(maxX - minX));
    fprintf(file, "closepath\n");
    fprintf(file, "clip\n");
    fprintf(file, "gsave newpath\n");

    fprintf(file, "%g %g translate\n", minX, minY);
    fprintf(file, "%g %g scale\n", sx*scale, sy*scale);
    fprintf(file, "%d %d 8\n", sx, sy);
    fprintf(file, "[%d 0 0 -%d 0 %d]\n", sx, sy, sy);
    fprintf(file, "{currentfile linestr readhexstring pop} %s\n",
            gray ? "image" : "false 3 colorimage");
    nrrdEncodingHex->write(file, nin->data, nrrdElementNumber(nin),
                           nin, nio);

    nio->dataFile = NULL;
    fprintf(file, "\n");

    fprintf(file, "grestore\n");
    if (width) {
        fprintf(file, "%g %g moveto\n", minX, minY);
        fprintf(file, "%g %g lineto\n", maxX, minY);
        fprintf(file, "%g %g lineto\n",
                (minX + maxX)/2, minY + hack*(maxX - minX));
        fprintf(file, "closepath\n");
        fprintf(file, "%g setlinewidth 0 setgray stroke\n",
                2*width*scale);
    }
    if (labels) {
        /* happily, psfrag doesn't respect the clipping path */
        fprintf(file, "/Helvetica findfont 20 scalefont setfont\n");
        fprintf(file, "%g %g moveto (A) show\n", maxX, minY);
        fprintf(file, "%g %g moveto (B) show\n", (minX + maxX)/2,
                minY + hack*(maxX - minX));
        fprintf(file, "%g %g moveto (C) show\n", minX, minY);
    }

    fprintf(file, "grestore\n");

    airMopOkay(mop);
    return 0;
}