int main(int argc, char *argv[]) { char *me; hestOpt *hopt; hestParm *hparm; airArray *mop; Nrrd *nin, *_nin; double *in, sym[21], eval[6], evec[36]; unsigned int rr, cc, ii, jj; me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hopt = NULL; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hestOptAdd(&hopt, NULL, "matrix", airTypeOther, 1, 1, &_nin, NULL, "6x6 matrix", NULL, NULL, nrrdHestNrrd); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, es6Info, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nin = nrrdNew(); airMopAdd(mop, nin, (airMopper)nrrdNuke, airMopAlways); if (!(2 == _nin->dim && 6 == _nin->axis[0].size && 6 == _nin->axis[1].size)) { fprintf(stderr, "%s: didn't get 2-D 6x6 matrix (got %u-D %ux%u)\n", me, _nin->dim, AIR_CAST(unsigned int, _nin->axis[0].size), AIR_CAST(unsigned int, _nin->axis[1].size)); airMopError(mop); return 1; }
int main(int argc, char *argv[]) { char *me, **name; int lenName, ni, reverse, quiet, noAction, mac; hestOpt *hopt = NULL; airArray *mop; me = argv[0]; hestOptAdd(&hopt, "r", NULL, airTypeInt, 0, 0, &reverse, NULL, "convert back to DOS, instead of converting from DOS to normal"); hestOptAdd(&hopt, "q", NULL, airTypeInt, 0, 0, &quiet, NULL, "never print anything to stderr, even for errors."); hestOptAdd(&hopt, "m", NULL, airTypeInt, 0, 0, &mac, NULL, "deal with legacy MAC text files."); hestOptAdd(&hopt, "n", NULL, airTypeInt, 0, 0, &noAction, NULL, "don't actually write converted files, just pretend to. " "This is useful to see which files WOULD be converted. "); hestOptAdd(&hopt, NULL, "file", airTypeString, 1, -1, &name, NULL, "all the files to convert. Each file will be over-written " "with its converted contents. Use \"-\" to read from stdin " "and write to stdout", &lenName); 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); for (ni=0; ni<lenName; ni++) { undosConvert(me, name[ni], reverse, mac, quiet, noAction); } airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me; hestOpt *hopt = NULL; int center; double minPos, maxPos, pos, index, size; me = argv[0]; hestOptAdd(&hopt, NULL, "center", airTypeEnum, 1, 1, ¢er, NULL, "which centering applies to the quantized position.\n " "Possibilities are:\n " "\b\bo \"cell\": for histogram bins, quantized values, and " "pixels-as-squares\n " "\b\bo \"node\": for non-trivially interpolated " "sample points", NULL, nrrdCenter); hestOptAdd(&hopt, NULL, "minPos", airTypeDouble, 1, 1, &minPos, NULL, "smallest position associated with index 0"); hestOptAdd(&hopt, NULL, "maxPos", airTypeDouble, 1, 1, &maxPos, NULL, "highest position associated with highest index"); hestOptAdd(&hopt, NULL, "num", airTypeDouble, 1, 1, &size, NULL, "number of intervals into which position has been quantized"); hestOptAdd(&hopt, NULL, "index", airTypeDouble, 1, 1, &index, NULL, "the input index, to be converted to position"); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); pos = NRRD_POS(center, minPos, maxPos, size, index); printf("%g\n", pos); hestParseFree(hopt); hestOptFree(hopt); exit(0); }
int main(int argc, char *argv[]) { char *me; hestOpt *hopt; hestParm *hparm; airArray *mop; int size[3]; me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hopt = NULL; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hestOptAdd(&hopt, "s", "sx sy sz", airTypeInt, 3, 3, size, "128 128 128", "dimensions of output volume"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, tmplInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); airMopOkay(mop); exit(0); }
int main(int argc, char *argv[]) { char *me; hestOpt *hopt=NULL; airArray *mop; unsigned int *srcA, *srcB, *dstC, *_srcA, *_srcB, numA, numB, numC, idx; me = argv[0]; hestOptAdd(&hopt, "a", "vals", airTypeUInt, 1, -1, &srcA, NULL, "list of values", &numA); hestOptAdd(&hopt, "b", "vals", airTypeUInt, 1, -1, &srcB, NULL, "list of values", &numB); 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); fprintf(stderr, "a ="); for (idx=0; idx<numA; idx++) { fprintf(stderr, " %u", srcA[idx]); } fprintf(stderr, "\n"); fprintf(stderr, "b ="); for (idx=0; idx<numB; idx++) { fprintf(stderr, " %u", srcB[idx]); } fprintf(stderr, "\n"); _srcA = AIR_CAST(unsigned int*, calloc(1+numA, sizeof(unsigned int))); airMopAdd(mop, _srcA, airFree, airMopAlways); _srcB = AIR_CAST(unsigned int*, calloc(1+numB, sizeof(unsigned int))); airMopAdd(mop, _srcB, airFree, airMopAlways); dstC = AIR_CAST(unsigned int*, calloc(1+AIR_MAX(numA,numB), sizeof(unsigned int))); airMopAdd(mop, dstC, airFree, airMopAlways); _srcA[0] = numA; for (idx=0; idx<numA; idx++) { _srcA[1+idx] = srcA[idx]; } _srcB[0] = numB; for (idx=0; idx<numB; idx++) { _srcB[1+idx] = srcB[idx]; } numC = flipListIntx(dstC, _srcA, _srcB); fprintf(stderr, "intx(a,b) ="); for (idx=0; idx<numC; idx++) { fprintf(stderr, " %u", dstC[idx]); } fprintf(stderr, "\n"); airMopOkay(mop); return 0; }
int main(int argc, const char *argv[]) { hestOpt *hopt=NULL; airArray *mop; const char *me; char *outS, *err; Nrrd *nin, *nout; NrrdIoState *nio; float heqamount; me = argv[0]; mop = airMopNew(); hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL, "input nrrd to project. Must be three dimensional.", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "amt", "heq", airTypeFloat, 1, 1, &heqamount, "0.5", "how much to apply histogram equalization to projection images"); hestOptAdd(&hopt, "o", "img out", airTypeString, 1, 1, &outS, NULL, "output image to save to. Will try to use whatever " "format is implied by extension, but will fall back to PPM."); 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); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); nio = nrrdIoStateNew(); airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways); nrrdStateDisableContent = AIR_TRUE; if (doit(nout, nin, 1, heqamount)) { err=biffGetDone(NINSPECT); airMopAdd(mop, err, airFree, airMopAlways); fprintf(stderr, "%s: trouble creating output:\n%s", me, err); airMopError(mop); return 1; } if (nrrdFormatPNG->nameLooksLike(outS) && !nrrdFormatPNG->available()) { fprintf(stderr, "(%s: using PPM format for output)\n", me); nio->format = nrrdFormatPNM; } if (nrrdSave(outS, nout, nio)) { err=biffGetDone(NRRD); airMopAdd(mop, err, airFree, airMopAlways); fprintf(stderr, "%s: trouble saving output image \"%s\":\n%s", me, outS, err); airMopError(mop); return 1; } airMopOkay(mop); return 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; }
int main(int argc, const char *argv[]) { airArray *mop; hestOpt *hopt=NULL; int i, N, M, P, yes, *year; unsigned int E; const char *me; double crct; me = argv[0]; mop = airMopNew(); hestOptAdd(&hopt, "N", "days", airTypeInt, 1, 1, &N, "365", "# of days in year"); /* E != P */ hestOptAdd(&hopt, "E", "exps", airTypeInt, 1, 1, &P, "100000", "number of experiments after which to print out newly " "computed probability"); hestOptAdd(&hopt, NULL, "people", airTypeInt, 1, 1, &M, NULL, "# of people in room"); 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 (!( N > 1 && M > 0 && P > 1)) { fprintf(stderr, "%s: need both M, P all > 1, M > 0\n", me); airMopError(mop); exit(1); } if (!(year = (int*)calloc(N, sizeof(int)))) { fprintf(stderr, "%s: couldn't calloc(%d,sizeof(int))\n", me, N); airMopError(mop); exit(1); } airMopMem(mop, year, airMopAlways); crct = 1; for (i=0; i<M; i++) { crct *= (double)(N-i)/N; } crct = 1-crct; yes = 0; E = 1; airSrandMT((int)airTime()); while (E) { yes += runexp(year, N, M); if (!(E % P)) { printf("P = %10d/%10d = %22.20f =?= %22.20f\n", yes, E, (double)yes/E, crct); } E++; } airMopOkay(mop); exit(0); }
int main(int argc, char *argv[]) { char *me; hestOpt *hopt=NULL; airArray *mop; int *itype, itypeNum, ii; double src[3], last[3], dst[3]; char space[] = " "; me = argv[0]; hestOptAdd(&hopt, NULL, "v1 v2 v3", airTypeDouble, 3, 3, src, NULL, "source triple"); hestOptAdd(&hopt, "t", "type", airTypeEnum, 2, -1, &itype, NULL, "sequence of triple types to convert through", &itypeNum, tenTripleType); 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); printf("%s", space + strlen(airEnumStr(tenTripleType, itype[0]))); printf("%s", airEnumStr(tenTripleType, itype[0])); ell_3v_print_d(stdout, src); ELL_3V_COPY(last, src); for (ii=1; ii<itypeNum; ii++) { tenTripleConvertSingle_d(dst, itype[ii], src, itype[ii-1]); printf("%s", space + strlen(airEnumStr(tenTripleType, itype[ii]))); printf("%s", airEnumStr(tenTripleType, itype[ii])); ell_3v_print_d(stdout, dst); ELL_3V_COPY(src, dst); } /* tenTripleConvert_d(dst, dstType, src, srcType); tenTripleConvert_d(tst, srcType, dst, dstType); */ /* printf("%s: %s %s --> %s --> %s\n", me, tenTriple->name, airEnumStr(tenTriple, srcType), airEnumStr(tenTriple, dstType), airEnumStr(tenTriple, srcType)); ell_3v_print_d(stdout, src); ell_3v_print_d(stdout, dst); ell_3v_print_d(stdout, tst); */ airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me, *outS, *err; hestOpt *hopt; hestParm *hparm; airArray *mop; Nrrd *_ninA, *_ninB, *ninA, *ninB, *nmul; me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hopt = NULL; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hestOptAdd(&hopt, NULL, "matrix", airTypeOther, 1, 1, &_ninA, NULL, "first matrix", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, NULL, "matrix", airTypeOther, 1, 1, &_ninB, NULL, "first matrix", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, "-", "file to write output nrrd to"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, mulInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); ninA = nrrdNew(); airMopAdd(mop, ninA, (airMopper)nrrdNuke, airMopAlways); ninB = nrrdNew(); airMopAdd(mop, ninB, (airMopper)nrrdNuke, airMopAlways); nmul = nrrdNew(); airMopAdd(mop, nmul, (airMopper)nrrdNuke, airMopAlways); nrrdConvert(ninA, _ninA, nrrdTypeDouble); nrrdConvert(ninB, _ninB, nrrdTypeDouble); if (ell_Nm_mul(nmul, ninA, ninB)) { airMopAdd(mop, err = biffGetDone(ELL), airFree, airMopAlways); fprintf(stderr, "%s: problem inverting:\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nmul, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: problem saving output:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); exit(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; }
int main(int argc, char *argv[]) { char *me; hestOpt *hopt=NULL; airArray *mop; pushEnergySpec *ensp; unsigned int pi, xi, nn; double xx, supp, del; mop = airMopNew(); me = argv[0]; hestOptAdd(&hopt, "energy", "spec", airTypeOther, 1, 1, &ensp, NULL, "specification of force function to use", NULL, NULL, pushHestEnergySpec); 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); fprintf(stderr, "%s: parsed energy \"%s\", with %u parms.\n", me, ensp->energy->name, ensp->energy->parmNum); for (pi=0; pi<ensp->energy->parmNum; pi++) { fprintf(stderr, "%u: %g\n", pi, ensp->parm[pi]); } fprintf(stderr, "\n"); nn = 600; supp = ensp->energy->support(ensp->parm); del = AIR_DELTA(0, 2, nn, 0, supp); for (xi=1; xi<nn; xi++) { double x0, x1, ee, ff, e0, e1, dummy; xx = AIR_AFFINE(0, xi, nn, 0, supp); x1 = AIR_AFFINE(0, xi+1, nn, 0, supp); x0 = AIR_AFFINE(0, xi-1, nn, 0, supp); ensp->energy->eval(&e1, &dummy, x1, ensp->parm); ensp->energy->eval(&e0, &dummy, x0, ensp->parm); ensp->energy->eval(&ee, &ff, xx, ensp->parm); printf("%g %g %g %g\n", xx, ee, ff, (e1 - e0)/del); } airMopOkay(mop); return 0; }
int rva_gridMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *hopt = NULL; char *err; airArray *mop; rvaLattSpec *lsp; double radius; char *outStr; Nrrd *nout; mop = airMopNew(); hopt = NULL; hestOptAdd(&hopt, NULL, "latt", airTypeOther, 1, 1, &lsp, NULL, "lattice definition", NULL, NULL, rvaHestLattSpec); hestOptAdd(&hopt, "r", "radius", airTypeDouble, 1, 1, &radius, "1", "radius limit"); hestOptAdd(&hopt, "o", "fname", airTypeString, 1, 1, &outStr, "-", "output filename"); hestParseOrDie(hopt, argc, argv, hparm, me, longInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (rvaGrid(nout, lsp, radius)) { airMopAdd(mop, err=biffGetDone(RVA), airFree, airMopAlways); fprintf(stderr, "%s: problem:\n%s", me, err); airMopError(mop); return 1; } if (nrrdSave(outStr, nout, NULL)) { airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: problem saving:\n%s", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int main(int argc, const char *argv[]) { const char *me, *info="inverts a moss transform"; hestOpt *hopt=NULL; double *mat, inv[6]; me = argv[0]; hestOptAdd(&hopt, "t", "transform", airTypeOther, 1, 1, &mat, "identity", "transform(s) to apply to image", NULL, NULL, mossHestTransform); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); fprintf(stderr, "%s: got transform:\n", me); mossMatPrint(stderr, mat); mossMatInvert(inv, mat); fprintf(stderr, "\n%s: inverse:\n", me); mossMatPrint(stderr, inv); exit(0); }
int main(int argc, char *argv[]) { char *me, *err; hestOpt *hopt=NULL; airArray *mop; char *outS; Nrrd *_ncov, *ncov, *_nten[2], *nten[2], *nout; double *cc, *t0, *t1, *out, ww[21]; size_t nn, ii; mop = airMopNew(); me = argv[0]; hestOptAdd(&hopt, "i4", "volume", airTypeOther, 1, 1, &_ncov, NULL, "4th-order tensor volume", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "i2", "v0 v1", airTypeOther, 2, 2, _nten, NULL, "two 2nd-order tensor volumes", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, "-", "file to write output nrrd to"); 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 (tenTensorCheck(_nten[0], nrrdTypeDefault, AIR_TRUE, AIR_TRUE) || tenTensorCheck(_nten[1], nrrdTypeDefault, AIR_TRUE, AIR_TRUE)) { airMopAdd(mop, err = biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: didn't like input:\n%s\n", me, err); airMopError(mop); return 1; } if (!(4 == _ncov->dim && 21 == _ncov->axis[0].size)) { fprintf(stderr, "%s: didn't get a 4-D 21-by-X volume (got %u-D %u-by-X)\n", me, _ncov->dim, AIR_CAST(unsigned int, _ncov->axis[0].size)); airMopError(mop); return 1; }
int main(int argc, char *argv[]) { char *me; hestOpt *hopt; hestParm *hparm; airArray *mop; char *err; Nrrd *nhist; double thresh, expo; me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hopt = NULL; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hestOptAdd(&hopt, "i", "nhist", airTypeOther, 1, 1, &nhist, NULL, "input histogram", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "e", "expo", airTypeDouble, 1, 1, &expo, "2.0", "exponent to use for variance calculation"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, otsuInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); if (nrrdHistoThresholdOtsu(&thresh, nhist, expo)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s", me, err); airMopError(mop); return 1; } fprintf(stderr, "%s: threshold = %g\n", me, thresh); airMopOkay(mop); exit(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 main(int argc, char *argv[]) { gageKind *kind; char *me, *outS, *err; hestParm *hparm; hestOpt *hopt = NULL; NrrdKernelSpec *ksp; int otype; unsigned int maxIter; double epsilon, lastDiff, step; Nrrd *nin, *nout; airArray *mop; mop = airMopNew(); me = argv[0]; hparm = hestParmNew(); airMopAdd(mop, hparm, AIR_CAST(airMopper, hestParmFree), airMopAlways); hparm->elideSingleOtherType = AIR_TRUE; hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL, "input volume", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "k", "kind", airTypeOther, 1, 1, &kind, NULL, "\"kind\" of volume (\"scalar\", \"vector\", " "\"tensor\", or \"dwi\")", NULL, NULL, &probeKindHestCB); hestOptAdd(&hopt, "k00", "kernel", airTypeOther, 1, 1, &ksp, NULL, "convolution kernel", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "mi", "max # iters", airTypeUInt, 1, 1, &maxIter, "100", "maximum number of iterations with which to compute the " "deconvolution"); hestOptAdd(&hopt, "e", "epsilon", airTypeDouble, 1, 1, &epsilon, "0.000001", "convergence threshold"); hestOptAdd(&hopt, "s", "step", airTypeDouble, 1, 1, &step, "1.0", "scaling of value update"); hestOptAdd(&hopt, "t", "type", airTypeOther, 1, 1, &otype, "default", "type to save output as. By default (not using this option), " "the output type is the same as the input type", NULL, NULL, &unrrduHestMaybeTypeCB); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output volume"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, deconvInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, AIR_CAST(airMopper, hestOptFree), airMopAlways); airMopAdd(mop, hopt, AIR_CAST(airMopper, hestParseFree), airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, AIR_CAST(airMopper, nrrdNuke), airMopAlways); if (gageDeconvolve(nout, &lastDiff, nin, kind, ksp, otype, maxIter, AIR_TRUE, step, epsilon, 1)) { airMopAdd(mop, err = biffGetDone(GAGE), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble saving output:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me, *err; hestOpt *hopt=NULL; airArray *mop; char *outS; double _tA[6], tA[7], _tB[6], tB[7], time0, time1, conv, confThresh, pA[3], pB[3], qA[4], qB[4], rA[9], rB[9], mat1[9], mat2[9], tmp, stepSize, minNorm, sclA, sclB; unsigned int NN, maxiter, refIdx[3]; int recurse, ptype, verb; Nrrd *_nin, *nin, *nout; tenInterpParm *tip; mop = airMopNew(); me = argv[0]; hestOptAdd(&hopt, "a", "tensor", airTypeDouble, 6, 6, _tA, "1 0 0 1 0 1", "first tensor"); hestOptAdd(&hopt, "pa", "qq", airTypeDouble, 3, 3, pA, "0 0 0", "rotation of first tensor"); hestOptAdd(&hopt, "sa", "scl", airTypeDouble, 1, 1, &sclA, "1.0", "scaling of first tensor"); hestOptAdd(&hopt, "b", "tensor", airTypeDouble, 6, 6, _tB, "1 0 0 1 0 1", "second tensor"); hestOptAdd(&hopt, "pb", "qq", airTypeDouble, 3, 3, pB, "0 0 0", "rotation of second tensor"); hestOptAdd(&hopt, "sb", "scl", airTypeDouble, 1, 1, &sclB, "1.0", "scaling of second tensor"); hestOptAdd(&hopt, "i", "nten", airTypeOther, 1, 1, &_nin, "", "input tensor volume (makes previous options moot)", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "ri", "x y z", airTypeUInt, 3, 3, refIdx, "0 0 0", "index of reference tensor in input tensor volume"); hestOptAdd(&hopt, "th", "thresh", airTypeDouble, 1, 1, &confThresh, "0.5", "conf mask threshold on \"-i\""); hestOptAdd(&hopt, "n", "# steps", airTypeUInt, 1, 1, &NN, "100", "number of steps in between two tensors"); hestOptAdd(&hopt, "s", "stepsize", airTypeDouble, 1, 1, &stepSize, "1", "step size in update"); hestOptAdd(&hopt, "mn", "minnorm", airTypeDouble, 1, 1, &minNorm, "0.000001", "minnorm of something"); hestOptAdd(&hopt, "c", "conv", airTypeDouble, 1, 1, &conv, "0.0001", "convergence threshold of length fraction"); hestOptAdd(&hopt, "mi", "maxiter", airTypeUInt, 1, 1, &maxiter, "0", "if non-zero, max # iterations for computation"); hestOptAdd(&hopt, "r", "recurse", airTypeInt, 0, 0, &recurse, NULL, "enable recursive solution, when useful"); hestOptAdd(&hopt, "t", "path type", airTypeEnum, 1, 1, &ptype, "lerp", "what type of path to compute", NULL, tenInterpType); hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, "-", "file to write output nrrd to"); hestOptAdd(&hopt, "v", "verbosity", airTypeInt, 1, 1, &verb, "0", "verbosity"); 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); tip = tenInterpParmNew(); airMopAdd(mop, tip, (airMopper)tenInterpParmNix, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); tip->verbose = verb; tip->convStep = stepSize; tip->enableRecurse = recurse; tip->minNorm = minNorm; tip->maxIter = maxiter; tip->convEps = conv; if (_nin) { double refTen[7], inTen[7], *in, *out; unsigned int xi, yi, zi, sx, sy, sz, dimOut; int axmap[NRRD_DIM_MAX], numerical; size_t size[NRRD_DIM_MAX]; if (tenTensorCheck(_nin, nrrdTypeDefault, AIR_TRUE, AIR_TRUE)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: input volume not valid:\n%s\n", me, err); airMopError(mop); return 1; } sx = AIR_CAST(unsigned int, _nin->axis[1].size); sy = AIR_CAST(unsigned int, _nin->axis[2].size); sz = AIR_CAST(unsigned int, _nin->axis[3].size); if (!( refIdx[0] < sx && refIdx[1] < sy && refIdx[2] < sz )) { fprintf(stderr, "%s: index (%u,%u,%u) out of bounds (%u,%u,%u)\n", me, refIdx[0], refIdx[1], refIdx[2], sx, sy, sz); airMopError(mop); return 1; } nin = nrrdNew(); airMopAdd(mop, nin, (airMopper)nrrdNuke, airMopAlways); numerical = (ptype == tenInterpTypeGeoLoxK || ptype == tenInterpTypeGeoLoxR || ptype == tenInterpTypeLoxK || ptype == tenInterpTypeLoxR || ptype == tenInterpTypeQuatGeoLoxK || ptype == tenInterpTypeQuatGeoLoxR); if (numerical) { tip->lengthFancy = AIR_TRUE; dimOut = 4; size[0] = 3; size[1] = _nin->axis[1].size; size[2] = _nin->axis[2].size; size[3] = _nin->axis[3].size; axmap[0] = -1; axmap[1] = 1; axmap[2] = 2; axmap[3] = 3; } else { dimOut = 3; size[0] = _nin->axis[1].size; size[1] = _nin->axis[2].size; size[2] = _nin->axis[3].size; axmap[0] = 1; axmap[1] = 2; axmap[2] = 3; } if (nrrdConvert(nin, _nin, nrrdTypeDouble) || nrrdMaybeAlloc_nva(nout, nrrdTypeDouble, dimOut, size) || nrrdAxisInfoCopy(nout, nin, axmap, NRRD_AXIS_INFO_SIZE_BIT) || nrrdBasicInfoCopy(nout, nin, (NRRD_BASIC_INFO_DATA_BIT | NRRD_BASIC_INFO_TYPE_BIT | NRRD_BASIC_INFO_DIMENSION_BIT | NRRD_BASIC_INFO_CONTENT_BIT | NRRD_BASIC_INFO_SAMPLEUNITS_BIT))) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } in = AIR_CAST(double *, nin->data); out = AIR_CAST(double *, nout->data); TEN_T_COPY(refTen, in + 7*(refIdx[0] + sx*(refIdx[1] + sy*refIdx[2]))); fprintf(stderr, "!%s: reference tensor = (%g) %g %g %g %g %g %g\n", me, refTen[0], refTen[1], refTen[2], refTen[3], refTen[4], refTen[5], refTen[6]); for (zi=0; zi<sz; zi++) { for (yi=0; yi<sy; yi++) { for (xi=0; xi<sx; xi++) { TEN_T_COPY(inTen, in + 7*(xi + sx*(yi + sy*zi))); if (numerical) { fprintf(stderr, "!%s: %u %u %u \n", me, xi, yi, zi); if (inTen[0] < confThresh) { out[0] = AIR_NAN; out[1] = AIR_NAN; out[2] = AIR_NAN; } else { tip->verbose = 10*(xi == refIdx[0] && yi == refIdx[1] && zi == refIdx[2]); out[0] = tenInterpDistanceTwo_d(inTen, refTen, ptype, tip); out[1] = tip->lengthShape; out[2] = tip->lengthOrient; } out += 3; } else { if (inTen[0] < confThresh) { *out = AIR_NAN; } else { *out = tenInterpDistanceTwo_d(inTen, refTen, ptype, tip); } out += 1; } } if (numerical) { if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble saving output:\n%s\n", me, err); airMopError(mop); return 1; } } } } } else {
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, >ype, "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; }
int main(int argc, char *argv[]) { char *me, *outS; hestOpt *hopt; hestParm *hparm; airArray *mop; char *err, done[13]; Nrrd *nin, *ndist, *nmask, *nupdate, *nout; NrrdKernelSpec *k00, *k11, *k22; int E; unsigned int sx, sy, sz, xi, yi, zi, si, iter, maxIter; gageContext *ctx; gagePerVolume *pvl; double dt, *dist, *mask, *update, thresh, eps, rmsMin; const double *valu, *gmag, *mcrv; me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hopt = NULL; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL, "input volume", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "k00", "kernel", airTypeOther, 1, 1, &k00, "tent", "k00", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "k11", "kernel", airTypeOther, 1, 1, &k11, "cubicd:0,0.5", "k00", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "k22", "kernel", airTypeOther, 1, 1, &k22, "cubicdd:1,0", "k00", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "dt", "step", airTypeDouble, 1, 1, &dt, "0.17", "time step size"); hestOptAdd(&hopt, "th", "val", airTypeDouble, 1, 1, &thresh, "0.0", "the value to use for thresholding the input " "volume, to create the binary constraint image."); hestOptAdd(&hopt, "eps", "val", airTypeDouble, 1, 1, &eps, "0.05", "width of value bracket around threshold, to constrain the " "the update from letting to value, originally on either " "side of the threshold, from getting too close."); hestOptAdd(&hopt, "rms", "thresh", airTypeDouble, 1, 1, &rmsMin, "0.01", "RMS change below this terminates updates."); hestOptAdd(&hopt, "mi", "max", airTypeUInt, 1, 1, &maxIter, "100", "maximum # iterations"); hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, "-", "fixed volume output"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, aaliasInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); ndist = nrrdNew(); nmask = nrrdNew(); nupdate = nrrdNew(); airMopAdd(mop, ndist, (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, nmask, (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, nupdate, (airMopper)nrrdNuke, airMopAlways); if (nrrdConvert(ndist, nin, nrrdTypeDouble) || nrrdConvert(nmask, nin, nrrdTypeDouble) || nrrdConvert(nupdate, nin, nrrdTypeDouble)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: couldn't allocate buffers:\n%s", me, err); airMopError(mop); return 1; } dist = AIR_CAST(double *, ndist->data); mask = AIR_CAST(double *, nmask->data); update = AIR_CAST(double *, nupdate->data); ctx = gageContextNew(); airMopAdd(mop, ctx, (airMopper)gageContextNix, airMopAlways); gageParmSet(ctx, gageParmRenormalize, AIR_TRUE); gageParmSet(ctx, gageParmCheckIntegrals, AIR_TRUE); E = 0; if (!E) E |= !(pvl = gagePerVolumeNew(ctx, ndist, gageKindScl)); if (!E) E |= gagePerVolumeAttach(ctx, pvl); if (!E) E |= gageKernelSet(ctx, gageKernel00, k00->kernel, k00->parm); if (!E) E |= gageKernelSet(ctx, gageKernel11, k11->kernel, k11->parm); if (!E) E |= gageKernelSet(ctx, gageKernel22, k22->kernel, k22->parm); if (!E) E |= gageQueryItemOn(ctx, pvl, gageSclValue); if (!E) E |= gageQueryItemOn(ctx, pvl, gageSclGradMag); if (!E) E |= gageQueryItemOn(ctx, pvl, gageSclMeanCurv); if (!E) E |= gageUpdate(ctx); if (E) { airMopAdd(mop, err = biffGetDone(GAGE), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } valu = gageAnswerPointer(ctx, pvl, gageSclValue); gmag = gageAnswerPointer(ctx, pvl, gageSclGradMag); mcrv = gageAnswerPointer(ctx, pvl, gageSclMeanCurv); sx = nin->axis[0].size; sy = nin->axis[1].size; sz = nin->axis[2].size; for (iter=0; iter<maxIter; iter++) { double rms; unsigned count; fprintf(stderr, "%s: iter %u: ", me, iter); fflush(stderr); for (zi=0; zi<sz; zi++) { fprintf(stderr, "%s", airDoneStr(0, zi, sz-1, done)); fflush(stderr); for (yi=0; yi<sy; yi++) { for (xi=0; xi<sx; xi++) { si = xi + sx*(yi + sy*zi); gageProbe(ctx, xi, yi, zi); update[si] = -dt*(*gmag)*(*mcrv); } } } rms = 0; count = 0; for (si=0; si<sx*sy*sz; si++) { double newval; if (update[si]) { /* NOTE: this update behavior is only slightly different than what's described in Equation 18 of the paper. That update rule ensures that the value never changes "sign" (with respect to the threshold value), by clamping the values above or below to 0.0. But worst-case scenario is that two adjacent samples that were on other side of the threshold (i.e. 0), could then equal the threshold, which would confuse a marching-cubes type algorithm. So the "eps" enforces a small value range around the treshold, and keeps the values on either side of it. */ newval = dist[si] + update[si]; if (mask[si] > thresh) { newval = AIR_MAX(newval, thresh+eps/2); } else { newval = AIR_MIN(newval, thresh-eps/2); } rms += (dist[si] - newval)*(dist[si] - newval); dist[si] = newval; count++; } } fprintf(stderr, "%s", airDoneStr(0, zi, sz-1, done)); rms /= count; rms = sqrt(rms); if (rms < rmsMin) { fprintf(stderr, "\n%s: RMS %g below threshold %g\n", me, rms, rmsMin); break; } else { fprintf(stderr, " rms = %g > %g\n", rms, rmsMin); } } if (iter == maxIter) { fprintf(stderr, "%s: hit max iter %u\n", me, maxIter); } nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdCopy(nout, ndist)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: couldn't allocate output:\n%s", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: couldn't save output:\n%s", me, err); airMopError(mop); return 1; } airMopOkay(mop); exit(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; }
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); }
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; }
int main(int argc, const char *argv[]) { const char *me; char *err, *out; int size[3], xi, yi, zi; hestOpt *hopt; hestParm *hparm; airArray *mop; float min[3], max[3], AB[2], x, y, z, *data, off; Nrrd *nout; me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hopt = NULL; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hestOptAdd(&hopt, "s", "sx sy sz", airTypeInt, 3, 3, size, "128 128 128", "dimensions of output volume"); hestOptAdd(&hopt, "min", "x y z", airTypeFloat, 3, 3, min, "-1 -1 -1", "lower bounding corner of volume"); hestOptAdd(&hopt, "max", "x y z", airTypeFloat, 3, 3, max, "1 1 1", "upper bounding corner of volume"); hestOptAdd(&hopt, "c", "A B", airTypeFloat, 2, 2, AB, NULL, "A and B quadratic coefficients"); hestOptAdd(&hopt, "off", "z offset", airTypeFloat, 1, 1, &off, "0.0", "vertical offset"); hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &out, "-", "file to write output nrrd to"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, quadInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdAlloc_va(nout, nrrdTypeFloat, 3, AIR_CAST(size_t, size[0]), AIR_CAST(size_t, size[1]), AIR_CAST(size_t, size[2]))) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: problem allocating volume:\n%s\n", me, err); airMopError(mop); return 1; } data = (float *)nout->data; for (zi=0; zi<size[2]; zi++) { z = AIR_AFFINE(0, zi, size[2]-1, min[2], max[2]); for (yi=0; yi<size[1]; yi++) { y = AIR_AFFINE(0, yi, size[1]-1, min[1], max[1]); for (xi=0; xi<size[0]; xi++) { x = AIR_AFFINE(0, xi, size[0]-1, min[0], max[0]); *data = quadFunc(x,y,z, AB[0], AB[1], off); data += 1; } } } nrrdAxisInfoSet_va(nout, nrrdAxisInfoMin, min[0], min[1], min[2]); nrrdAxisInfoSet_va(nout, nrrdAxisInfoMax, max[0], max[1], max[2]); nrrdAxisInfoSpacingSet(nout, 0); nrrdAxisInfoSpacingSet(nout, 1); nrrdAxisInfoSpacingSet(nout, 2); if (nrrdSave(out, nout, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: problem saving output:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); exit(0); }
int main(int argc, char *argv[]) { gageKind *kind; char *me, *whatS, *err, *outS, *stackSavePath; hestParm *hparm; hestOpt *hopt = NULL; NrrdKernelSpec *k00, *k11, *k22, *kSS, *kSSblur; float pos[3], lineInfo[4]; double gmc, rangeSS[2], posSS, *scalePos; unsigned int ansLen, numSS, ninSSIdx, lineStepNum; int what, E=0, renorm, SSrenorm, SSuniform, verbose; const double *answer; Nrrd *nin, **ninSS=NULL, *nout=NULL; gageContext *ctx; gagePerVolume *pvl; limnPolyData *lpld=NULL; airArray *mop; int worldSpace; Nrrd *ngrad=NULL, *nbmat=NULL; double bval, eps; unsigned int *skip, skipNum; mop = airMopNew(); me = argv[0]; hparm = hestParmNew(); airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hparm->elideSingleOtherType = AIR_TRUE; hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL, "input volume", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "k", "kind", airTypeOther, 1, 1, &kind, NULL, "\"kind\" of volume (\"scalar\", \"vector\", or \"tensor\")", NULL, NULL, &probeKindHestCB); hestOptAdd(&hopt, "p", "x y z", airTypeFloat, 3, 3, pos, NULL, "the position in space at which to probe"); hestOptAdd(&hopt, "wsp", NULL, airTypeInt, 0, 0, &worldSpace, NULL, "if using this option, position (\"-p\") will be in world " "space, instead of index space (the default)"); hestOptAdd(&hopt, "pi", "lpld in", airTypeOther, 1, 1, &lpld, "", "input polydata (overrides \"-p\")", NULL, NULL, limnHestPolyDataLMPD); hestOptAdd(&hopt, "pl", "x y z s", airTypeFloat, 4, 4, lineInfo, "0 0 0 0", "probe along line, instead of at point. " "The \"-p\" three coords are the line start point. " "If \"s\" is zero, (x,y,z) is the line end point. " "If \"s\" is non-zero, (x,y,z) is the line direction, " "which is scaled to have length \"s\", " "and then used as the step between line samples. "); hestOptAdd(&hopt, "pln", "num", airTypeUInt, 1, 1, &lineStepNum, "0", "if non-zero, number of steps of probing to do along line, " "which overrides \"-p\" and \"-pi\""); hestOptAdd(&hopt, "v", "verbosity", airTypeInt, 1, 1, &verbose, "1", "verbosity level"); hestOptAdd(&hopt, "q", "query", airTypeString, 1, 1, &whatS, NULL, "the quantity (scalar, vector, or matrix) to learn by probing"); hestOptAdd(&hopt, "eps", "epsilon", airTypeDouble, 1, 1, &eps, "0", "if non-zero, and if query is a scalar, epsilon around probe " "location where we will do discrete differences to find the " "gradient and hessian (for debugging)"); hestOptAdd(&hopt, "k00", "kern00", airTypeOther, 1, 1, &k00, "tent", "kernel for gageKernel00", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "k11", "kern11", airTypeOther, 1, 1, &k11, "cubicd:1,0", "kernel for gageKernel11", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "k22", "kern22", airTypeOther, 1, 1, &k22, "cubicdd:1,0", "kernel for gageKernel22", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "ssn", "SS #", airTypeUInt, 1, 1, &numSS, "0", "how many scale-space samples to evaluate, or, " "0 to turn-off all scale-space behavior"); hestOptAdd(&hopt, "ssr", "scale range", airTypeDouble, 2, 2, rangeSS, "nan nan", "range of scales in scale-space"); hestOptAdd(&hopt, "sss", "scale save path", airTypeString, 1, 1, &stackSavePath, "", "give a non-empty path string (like \"./\") to save out " "the pre-blurred volumes computed for the stack"); hestOptAdd(&hopt, "ssp", "SS pos", airTypeDouble, 1, 1, &posSS, "0", "position at which to sample in scale-space"); hestOptAdd(&hopt, "kssblur", "kernel", airTypeOther, 1, 1, &kSSblur, "dgauss:1,5", "blurring kernel, to sample scale space", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "kss", "kernel", airTypeOther, 1, 1, &kSS, "tent", "kernel for reconstructing from scale space samples", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "ssrn", "ssrn", airTypeInt, 1, 1, &SSrenorm, "0", "enable derivative normalization based on scale space"); hestOptAdd(&hopt, "ssu", NULL, airTypeInt, 0, 0, &SSuniform, NULL, "do uniform samples along sigma, and not (by default) " "samples according to the logarithm of diffusion time"); hestOptAdd(&hopt, "rn", NULL, airTypeInt, 0, 0, &renorm, NULL, "renormalize kernel weights at each new sample location. " "\"Accurate\" kernels don't need this; doing it always " "makes things go slower"); hestOptAdd(&hopt, "gmc", "min gradmag", airTypeDouble, 1, 1, &gmc, "0.0", "For curvature-based queries, use zero when gradient " "magnitude is below this"); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output array, when probing on polydata vertices"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, probeInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); what = airEnumVal(kind->enm, whatS); if (!what) { /* 0 indeed always means "unknown" for any gageKind */ fprintf(stderr, "%s: couldn't parse \"%s\" as measure of \"%s\" volume\n", me, whatS, kind->name); hestUsage(stderr, hopt, me, hparm); hestGlossary(stderr, hopt, hparm); airMopError(mop); return 1; } if (ELL_4V_LEN(lineInfo) && !lineStepNum) { fprintf(stderr, "%s: gave line info (\"-pl\") but not " "# samples (\"-pln\")", me); hestUsage(stderr, hopt, me, hparm); hestGlossary(stderr, hopt, hparm); airMopError(mop); return 1; } /* special set-up required for DWI kind */ if (!strcmp(TEN_DWI_GAGE_KIND_NAME, kind->name)) { if (tenDWMRIKeyValueParse(&ngrad, &nbmat, &bval, &skip, &skipNum, nin)) { airMopAdd(mop, err = biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble parsing DWI info:\n%s\n", me, err); airMopError(mop); return 1; } if (skipNum) { fprintf(stderr, "%s: sorry, can't do DWI skipping in tenDwiGage", me); airMopError(mop); return 1; } /* this could stand to use some more command-line arguments */ if (tenDwiGageKindSet(kind, 50, 1, bval, 0.001, ngrad, nbmat, tenEstimate1MethodLLS, tenEstimate2MethodQSegLLS, /* randSeed */ 7919)) { airMopAdd(mop, err = biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble parsing DWI info:\n%s\n", me, err); airMopError(mop); return 1; } } ansLen = kind->table[what].answerLength; /* for setting up pre-blurred scale-space samples */ if (numSS) { unsigned int vi; ninSS = AIR_CAST(Nrrd **, calloc(numSS, sizeof(Nrrd *))); scalePos = AIR_CAST(double *, calloc(numSS, sizeof(double))); if (!(ninSS && scalePos)) { fprintf(stderr, "%s: couldn't allocate ninSS", me); airMopError(mop); return 1; } for (ninSSIdx=0; ninSSIdx<numSS; ninSSIdx++) { ninSS[ninSSIdx] = nrrdNew(); airMopAdd(mop, ninSS[ninSSIdx], (airMopper)nrrdNuke, airMopAlways); } if (SSuniform) { for (vi=0; vi<numSS; vi++) { scalePos[vi] = AIR_AFFINE(0, vi, numSS-1, rangeSS[0], rangeSS[1]); } } else { double rangeTau[2], tau; rangeTau[0] = gageTauOfSig(rangeSS[0]); rangeTau[1] = gageTauOfSig(rangeSS[1]); for (vi=0; vi<numSS; vi++) { tau = AIR_AFFINE(0, vi, numSS-1, rangeTau[0], rangeTau[1]); scalePos[vi] = gageSigOfTau(tau); } } if (verbose > 2) { fprintf(stderr, "%s: sampling scale range %g--%g %suniformly:\n", me, rangeSS[0], rangeSS[1], SSuniform ? "" : "non-"); for (vi=0; vi<numSS; vi++) { fprintf(stderr, " scalePos[%u] = %g\n", vi, scalePos[vi]); } } if (gageStackBlur(ninSS, scalePos, numSS, nin, kind->baseDim, kSSblur, nrrdBoundaryBleed, AIR_TRUE, verbose)) { airMopAdd(mop, err = biffGetDone(GAGE), airFree, airMopAlways); fprintf(stderr, "%s: trouble pre-computing blurrings:\n%s\n", me, err); airMopError(mop); return 1; } if (airStrlen(stackSavePath)) { char fnform[AIR_STRLEN_LARGE]; sprintf(fnform, "%s/blur-%%02u.nrrd", stackSavePath); fprintf(stderr, "%s: |%s|\n", me, fnform); if (nrrdSaveMulti(fnform, AIR_CAST(const Nrrd *const *, ninSS), numSS, 0, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble saving blurrings:\n%s\n", me, err); airMopError(mop); return 1; } } } else {
int main(int argc, const char **argv) { const char *me; char *err; hestOpt *hopt=NULL; hestParm *hparm; airArray *mop; /* variables learned via hest */ Nrrd *nin; float camfr[3], camat[3], camup[3], camnc, camfc, camFOV; int camortho, hitandquit; unsigned int camsize[2]; double isovalue, sliso, isomin, isomax; /* boilerplate hest code */ me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hparm->respFileEnable = AIR_TRUE; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); /* setting up the command-line options */ hparm->respFileEnable = AIR_TRUE; hestOptAdd(&hopt, "i", "volume", airTypeOther, 1, 1, &nin, NULL, "input volume to isosurface", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "v", "isovalue", airTypeDouble, 1, 1, &isovalue, "nan", "isovalue at which to run Marching Cubes"); hestOptAdd(&hopt, "fr", "x y z", airTypeFloat, 3, 3, camfr, "3 4 5", "look-from point"); hestOptAdd(&hopt, "at", "x y z", airTypeFloat, 3, 3, camat, "0 0 0", "look-at point"); hestOptAdd(&hopt, "up", "x y z", airTypeFloat, 3, 3, camup, "0 0 1", "up direction"); hestOptAdd(&hopt, "nc", "dist", airTypeFloat, 1, 1, &(camnc), "-2", "at-relative near clipping distance"); hestOptAdd(&hopt, "fc", "dist", airTypeFloat, 1, 1, &(camfc), "2", "at-relative far clipping distance"); hestOptAdd(&hopt, "fov", "angle", airTypeFloat, 1, 1, &(camFOV), "20", "vertical field-of-view, in degrees. Full vertical " "extent of image plane subtends this angle."); hestOptAdd(&hopt, "sz", "s0 s1", airTypeUInt, 2, 2, &(camsize), "640 480", "# samples (horz vert) of image plane. "); hestOptAdd(&hopt, "ortho", NULL, airTypeInt, 0, 0, &(camortho), NULL, "use orthographic instead of (the default) " "perspective projection "); hestOptAdd(&hopt, "haq", NULL, airTypeBool, 0, 0, &(hitandquit), NULL, "save a screenshot rather than display the viewer"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, "demo program", AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); /* learn value range, and set initial isovalue if needed */ NrrdRange *range = nrrdRangeNewSet(nin, AIR_FALSE); airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways); isomin = range->min; isomax = range->max; if (!AIR_EXISTS(isovalue)) { isovalue = (isomin + isomax)/2; } /* first, make sure we can isosurface ok */ limnPolyData *lpld = limnPolyDataNew(); seekContext *sctx = seekContextNew(); airMopAdd(mop, sctx, (airMopper)seekContextNix, airMopAlways); sctx->pldArrIncr = nrrdElementNumber(nin); seekVerboseSet(sctx, 0); seekNormalsFindSet(sctx, AIR_TRUE); if (seekDataSet(sctx, nin, NULL, 0) || seekTypeSet(sctx, seekTypeIsocontour) || seekIsovalueSet(sctx, isovalue) || seekUpdate(sctx) || seekExtract(sctx, lpld)) { airMopAdd(mop, err=biffGetDone(SEEK), airFree, airMopAlways); fprintf(stderr, "trouble with isosurfacing:\n%s", err); airMopError(mop); return 1; } if (!lpld->xyzwNum) { fprintf(stderr, "%s: warning: No isocontour generated at isovalue %g\n", me, isovalue); } /* then create empty scene */ Hale::init(); Hale::Scene scene; /* then create viewer (in order to create the OpenGL context) */ Hale::Viewer viewer(camsize[0], camsize[1], "Iso", &scene); viewer.lightDir(glm::vec3(-1.0f, 1.0f, 3.0f)); viewer.camera.init(glm::vec3(camfr[0], camfr[1], camfr[2]), glm::vec3(camat[0], camat[1], camat[2]), glm::vec3(camup[0], camup[1], camup[2]), camFOV, (float)camsize[0]/camsize[1], camnc, camfc, camortho); viewer.refreshCB((Hale::ViewerRefresher)render); viewer.refreshData(&viewer); sliso = isovalue; viewer.slider(&sliso, isomin, isomax); viewer.current(); /* then create geometry, and add it to scene */ Hale::Polydata hply(lpld, true, // hply now owns lpld Hale::ProgramLib(Hale::preprogramAmbDiff2SideSolid)); scene.add(&hply); scene.drawInit(); render(&viewer); if (hitandquit) { seekIsovalueSet(sctx, isovalue); seekUpdate(sctx); seekExtract(sctx, lpld); hply.rebuffer(); render(&viewer); glfwWaitEvents(); render(&viewer); viewer.snap(); Hale::done(); airMopOkay(mop); return 0; } while(!Hale::finishing){ glfwWaitEvents(); if (viewer.sliding() && sliso != isovalue) { isovalue = sliso; printf("%s: isosurfacing at %g\n", me, isovalue); seekIsovalueSet(sctx, isovalue); seekUpdate(sctx); seekExtract(sctx, lpld); hply.rebuffer(); } render(&viewer); } /* clean exit; all okay */ Hale::done(); airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me; hestOpt *hopt=NULL; airArray *mop; double tripA[3], tripB[3], evalA[3], evalB[3], rt_A[3], rt_B[3], trip[3], eval[3], lasteval[3], lastxyz[3], logAB[3], ndist; int ittype, ottype, ptype, rttype; unsigned int NN, ii; tenInterpParm *tip; void (*interp)(double oeval[3], const double evalA[3], const double evalB[3], const double tt); double (*qdist)(const double RTh_A[3], const double RTh_B[3]); void (*qlog)(double klog[3], const double RThZA[3], const double RThZB[3]); void (*qexp)(double RThZB[3], const double RThZA[3], const double klog[3]); void (*grads)(double grad[3][3], const double eval[3]); me = argv[0]; mop = airMopNew(); tip = tenInterpParmNew(); airMopAdd(mop, tip, (airMopper)tenInterpParmNix, airMopAlways); hestOptAdd(&hopt, "a", "start", airTypeDouble, 3, 3, tripA, NULL, "start triple of values"); hestOptAdd(&hopt, "b", "end", airTypeDouble, 3, 3, tripB, NULL, "end triple of values"); hestOptAdd(&hopt, "it", "type", airTypeEnum, 1, 1, &ittype, NULL, "type of given start and end triples", NULL, tenTripleType); hestOptAdd(&hopt, "ot", "type", airTypeEnum, 1, 1, &ottype, NULL, "type of triples for output", NULL, tenTripleType); hestOptAdd(&hopt, "p", "type", airTypeEnum, 1, 1, &ptype, NULL, "type of path interpolation", NULL, tenInterpType); hestOptAdd(&hopt, "n", "# steps", airTypeUInt, 1, 1, &NN, "100", "number of steps along path"); hestOptAdd(&hopt, "v", "verbosity", airTypeInt, 1, 1, &(tip->verbose), "0", "verbosity"); hestOptAdd(&hopt, "s", "stepsize", airTypeDouble, 1, 1, &(tip->convStep), "1", "step size in update"); hestOptAdd(&hopt, "r", "recurse", airTypeInt, 0, 0, &(tip->enableRecurse), NULL, "enable recursive solution, when useful"); hestOptAdd(&hopt, "mn", "minnorm", airTypeDouble, 1, 1, &(tip->minNorm), "0.000001", "minnorm of something"); hestOptAdd(&hopt, "mi", "maxiter", airTypeUInt, 1, 1, &(tip->maxIter), "0", "if non-zero, max # iterations for computation"); hestOptAdd(&hopt, "c", "conv", airTypeDouble, 1, 1, &(tip->convEps), "0.0001", "convergence threshold of length fraction"); 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 (!( tenInterpTypeQuatGeoLoxK == ptype || tenInterpTypeQuatGeoLoxR == ptype )) { fprintf(stderr, "%s: need type %s or %s, not %s\n", me, airEnumStr(tenInterpType, tenInterpTypeQuatGeoLoxK), airEnumStr(tenInterpType, tenInterpTypeQuatGeoLoxR), airEnumStr(tenInterpType, ptype)); airMopError(mop); return 1; } if (tenInterpTypeQuatGeoLoxK == ptype) { interp = tenQGLInterpTwoEvalK; qdist = _tenQGL_Kdist; qlog = _tenQGL_Klog; qexp = _tenQGL_Kexp; grads = kgrads; rttype = tenTripleTypeRThetaZ; } else { interp = tenQGLInterpTwoEvalR; qdist = _tenQGL_Rdist; qlog = _tenQGL_Rlog; qexp = _tenQGL_Rexp; grads = rgrads; rttype = tenTripleTypeRThetaPhi; } fprintf(stderr, "%s: (%s) %f %f %f \n--%s--> %f %f %f\n", me, airEnumStr(tenTripleType, ittype), tripA[0], tripA[1], tripA[2], airEnumStr(tenInterpType, ptype), tripB[0], tripB[1], tripB[2]); tenTripleConvertSingle_d(evalA, tenTripleTypeEigenvalue, tripA, ittype); tenTripleConvertSingle_d(evalB, tenTripleTypeEigenvalue, tripB, ittype); tenTripleConvertSingle_d(rt_A, rttype, tripA, ittype); tenTripleConvertSingle_d(rt_B, rttype, tripB, ittype); ndist = 0; ELL_3V_SET(lasteval, AIR_NAN, AIR_NAN, AIR_NAN); ELL_3V_SET(lastxyz, AIR_NAN, AIR_NAN, AIR_NAN); qlog(logAB, rt_A, rt_B); fprintf(stderr, "%s: log = %g %g %g (%g)\n", me, logAB[0], logAB[1], logAB[2], ELL_3V_LEN(logAB)); for (ii=0; ii<NN; ii++) { double tt, xyz[3], dot[3], ll[3], prayRT[3], prayO[3]; tt = AIR_AFFINE(0, ii, NN-1, 0.0, 1.0); interp(eval, evalA, evalB, tt); tenTripleConvertSingle_d(trip, ottype, eval, tenTripleTypeEigenvalue); tenTripleConvertSingle_d(xyz, tenTripleTypeXYZ, eval, tenTripleTypeEigenvalue); ELL_3V_SCALE(ll, tt, logAB); qexp(prayRT, rt_A, ll); tenTripleConvertSingle_d(prayO, ottype, prayRT, rttype); if (ii) { double diff[3], gr[3][3]; ELL_3V_SUB(diff, lasteval, eval); ndist += ELL_3V_LEN(diff); ELL_3V_SUB(diff, lastxyz, xyz); grads(gr, eval); dot[0] = ELL_3V_DOT(diff, gr[0]); dot[1] = ELL_3V_DOT(diff, gr[1]); dot[2] = ELL_3V_DOT(diff, gr[2]); } else { ELL_3V_SET(dot, 0, 0, 0); } printf("%03u %g %g %g %g %g %g 00 %g %g %g\n", ii, trip[0], prayO[0], trip[1], prayO[1], trip[2], prayO[2], dot[0], dot[1], dot[2]); ELL_3V_COPY(lasteval, eval); ELL_3V_COPY(lastxyz, xyz); } fprintf(stderr, "%s: dist %g =?= %g\n", me, qdist(rt_A, rt_B), ndist); airMopOkay(mop); return 0; }
int main(int argc, const char *argv[]) { const char *me; char *err, *outS; hestOpt *hopt=NULL; airArray *mop; int xi, yi, zi, samp; float *tdata; double clp[2], xyz[3], q[4], len; double mD[9], mRF[9], mRI[9], mT[9]; Nrrd *nten; mop = airMopNew(); me = argv[0]; hestOptAdd(&hopt, "n", "# samples", airTypeInt, 1, 1, &samp, "4", "number of samples along each edge of cube"); hestOptAdd(&hopt, "c", "cl cp", airTypeDouble, 2, 2, clp, NULL, "shape of tensor to use; \"cl\" and \"cp\" are cl1 " "and cp1 values, both in [0.0,1.0]"); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output file to save tensors 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); nten = nrrdNew(); airMopAdd(mop, nten, (airMopper)nrrdNuke, airMopAlways); _clp2xyz(xyz, clp); fprintf(stderr, "%s: want evals = %g %g %g\n", me, xyz[0], xyz[1], xyz[2]); if (nrrdMaybeAlloc_va(nten, nrrdTypeFloat, 4, AIR_CAST(size_t, 7), AIR_CAST(size_t, samp), AIR_CAST(size_t, samp), AIR_CAST(size_t, samp))) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: couldn't allocate output:\n%s\n", me, err); airMopError(mop); return 1; } ELL_3M_IDENTITY_SET(mD); ELL_3M_DIAG_SET(mD, xyz[0], xyz[1], xyz[2]); tdata = (float*)nten->data; for (zi=0; zi<samp; zi++) { for (yi=0; yi<samp; yi++) { for (xi=0; xi<samp; xi++) { q[0] = 1.0; q[1] = AIR_AFFINE(-0.5, (float)xi, samp-0.5, -1, 1); q[2] = AIR_AFFINE(-0.5, (float)yi, samp-0.5, -1, 1); q[3] = AIR_AFFINE(-0.5, (float)zi, samp-0.5, -1, 1); len = ELL_4V_LEN(q); ELL_4V_SCALE(q, 1.0/len, q); washQtoM3(mRF, q); ELL_3M_TRANSPOSE(mRI, mRF); ELL_3M_IDENTITY_SET(mT); ell_3m_post_mul_d(mT, mRI); ell_3m_post_mul_d(mT, mD); ell_3m_post_mul_d(mT, mRF); tdata[0] = 1.0; TEN_M2T(tdata, mT); tdata += 7; } } } if (nrrdSave(outS, nten, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: couldn't save output:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me, *errS, *outS; hestOpt *hopt=NULL; hestParm *hparm; airArray *mop; Nrrd *nin, *nout; NrrdKernelSpec *ksp; mossSampler *msp; double mat[6], **matList, *origInfo, origMat[6], origInvMat[6], ox, oy, min[2], max[2]; int d, bound, ax0, size[2]; unsigned int matListLen, _bkgLen, i, avgNum; float *bkg, *_bkg, scale[4]; me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hparm->elideSingleEnumType = AIR_TRUE; hparm->elideSingleOtherType = AIR_TRUE; hparm->elideSingleOtherDefault = AIR_FALSE; hparm->elideMultipleNonExistFloatDefault = AIR_TRUE; hparm->respFileEnable = AIR_TRUE; hestOptAdd(&hopt, "i", "image", airTypeOther, 1, 1, &nin, "-", "input image", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "0", "origin", airTypeOther, 1, 1, &origInfo, "p:0,0", "where to location (0,0) prior to applying transforms.\n " "\b\bo \"u:<float>,<float>\" locate origin in a unit box " "[0,1]x[0,1] which covers the original image\n " "\b\bo \"p:<float>,<float>\" locate origin at a particular " "pixel location, in the index space of the image", NULL, NULL, mossHestOrigin); hestOptAdd(&hopt, "t", "xform0", airTypeOther, 1, -1, &matList, NULL, "transform(s) to apply to image. Transforms " "are applied in the order in which they appear.\n " "\b\bo \"identity\": no geometric transform, just resampling\n " "\b\bo \"translate:x,y\": shift image by vector (x,y), as " "measured in pixels\n " "\b\bo \"rotate:ang\": rotate CCW by ang degrees\n " "\b\bo \"scale:xs,ys\": scale by xs in X, and ys in Y\n " "\b\bo \"shear:fix,amnt\": shear by amnt, keeping fixed " "the pixels along a direction <fix> degrees from the X axis\n " "\b\bo \"flip:ang\": flip along axis an angle <ang> degrees from " "the X axis\n " "\b\bo \"a,b,tx,c,d,ty\": specify the transform explicitly " "in row-major order (opposite of PostScript) ", &matListLen, NULL, mossHestTransform); hestOptAdd(&hopt, "k", "kernel", airTypeOther, 1, 1, &ksp, "cubic:0,0.5", "reconstruction kernel", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "min", "xMin yMin", airTypeDouble, 2, 2, min, "nan nan", "lower bounding corner of output image. Default (by not " "using this option) is the lower corner of input image. "); hestOptAdd(&hopt, "max", "xMax yMax", airTypeDouble, 2, 2, max, "nan nan", "upper bounding corner of output image. Default (by not " "using this option) is the upper corner of input image. "); hestOptAdd(&hopt, "b", "boundary", airTypeEnum, 1, 1, &bound, "bleed", "what to do when sampling outside original image.\n " "\b\bo \"bleed\": copy values at image border outward\n " "\b\bo \"wrap\": do wrap-around on image locations\n " "\b\bo \"pad\": use a given background value (via \"-bg\")", NULL, nrrdBoundary); hestOptAdd(&hopt, "bg", "bg0 bg1", airTypeFloat, 1, -1, &_bkg, "nan", "background color to use with boundary behavior \"pad\". " "Defaults to all zeroes.", &_bkgLen); hestOptAdd(&hopt, "s", "xSize ySize", airTypeOther, 2, 2, scale, "x1 x1", "For each axis, information about how many samples in output:\n " "\b\bo \"x<float>\": number of output samples is some scaling of " " the number input of samples; multiplied by <float>\n " "\b\bo \"<int>\": specify exact number of samples", NULL, NULL, &unrrduHestScaleCB); hestOptAdd(&hopt, "a", "avg #", airTypeUInt, 1, 1, &avgNum, "0", "number of averages (if there there is only one " "rotation)"); hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, "-", "file to write output nrrd to"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, ilkInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); msp = mossSamplerNew(); airMopAdd(mop, msp, (airMopper)mossSamplerNix, airMopAlways); msp->boundary = bound; if (mossSamplerKernelSet(msp, ksp->kernel, ksp->parm)) { fprintf(stderr, "%s: trouble with sampler:\n%s\n", me, errS = biffGetDone(MOSS)); free(errS); airMopError(mop); return 1; } if (nrrdBoundaryPad == bound) { if (_bkgLen != MOSS_NCOL(nin)) { fprintf(stderr, "%s: got %d background colors, image has " _AIR_SIZE_T_CNV " colors\n", me, _bkgLen, MOSS_NCOL(nin)); airMopError(mop); return 1; } else { bkg = _bkg; } } else { /* maybe warn user if they gave a background that won't be used? */ /* No- because hest is stupid, and right now we always parse the single (default) "nan" for this argument! */ bkg = NULL; } ax0 = MOSS_AXIS0(nin); if (!( AIR_EXISTS(nin->axis[ax0+0].min) && AIR_EXISTS(nin->axis[ax0+0].max))) { nrrdAxisInfoMinMaxSet(nin, ax0+0, mossDefCenter); } if (!( AIR_EXISTS(nin->axis[ax0+1].min) && AIR_EXISTS(nin->axis[ax0+1].max))) { nrrdAxisInfoMinMaxSet(nin, ax0+1, mossDefCenter); } min[0] = AIR_EXISTS(min[0]) ? min[0] : nin->axis[ax0+0].min; max[0] = AIR_EXISTS(max[0]) ? max[0] : nin->axis[ax0+0].max; min[1] = AIR_EXISTS(min[1]) ? min[1] : nin->axis[ax0+1].min; max[1] = AIR_EXISTS(max[1]) ? max[1] : nin->axis[ax0+1].max; for (d=0; d<2; d++) { switch((int)scale[0 + 2*d]) { case 0: /* same number of samples as input */ size[d] = nin->axis[ax0+d].size; break; case 1: /* scaling of input # samples */ size[d] = (int)(scale[1 + 2*d]*nin->axis[ax0+d].size); break; case 2: /* explicit # of samples */ size[d] = (int)(scale[1 + 2*d]); break; } } /* find origin-based pre- and post- translate */ if (0 == origInfo[0]) { /* absolute pixel position */ mossMatTranslateSet(origMat, -origInfo[1], -origInfo[2]); } else { /* in unit box [0,1]x[0,1] */ ox = AIR_AFFINE(0.0, origInfo[1], 1.0, nin->axis[ax0+0].min, nin->axis[ax0+0].max); oy = AIR_AFFINE(0.0, origInfo[2], 1.0, nin->axis[ax0+1].min, nin->axis[ax0+1].max); mossMatTranslateSet(origMat, -ox, -oy); } mossMatInvert(origInvMat, origMat); /* form complete transform */ mossMatIdentitySet(mat); mossMatLeftMultiply(mat, origMat); for (i=0; i<matListLen; i++) { mossMatLeftMultiply(mat, matList[i]); } mossMatLeftMultiply(mat, origInvMat); if (!AIR_EXISTS(nin->axis[ax0+0].min) || !AIR_EXISTS(nin->axis[ax0+0].max)) { nrrdAxisInfoMinMaxSet(nin, ax0+0, mossDefCenter); } if (!AIR_EXISTS(nin->axis[ax0+1].min) || !AIR_EXISTS(nin->axis[ax0+1].max)) { nrrdAxisInfoMinMaxSet(nin, ax0+1, mossDefCenter); } if (avgNum > 1) { unsigned int ai; double angleMax, angle, mrot[6]; Nrrd *ntmp, *nacc; NrrdIter *itA, *itB; int E; ntmp = nrrdNew(); airMopAdd(mop, ntmp, (airMopper)nrrdNuke, airMopAlways); nacc = nrrdNew(); airMopAdd(mop, nacc, (airMopper)nrrdNuke, airMopAlways); itA = nrrdIterNew(); airMopAdd(mop, itA, (airMopper)nrrdIterNix, airMopAlways); itB = nrrdIterNew(); airMopAdd(mop, itB, (airMopper)nrrdIterNix, airMopAlways); E = 0; angleMax = atan2(mat[3], mat[0]); fprintf(stderr, "%s: %u angles ", me, avgNum); for (ai=0; ai<avgNum; ai++) { fprintf(stderr, "."); fflush(stderr); angle = (180/AIR_PI)*AIR_AFFINE(0, ai, avgNum-1, angleMax, -angleMax); mossMatIdentitySet(mat); mossMatLeftMultiply(mat, origMat); mossMatRotateSet(mrot, angle); mossMatLeftMultiply(mat, mrot); mossMatLeftMultiply(mat, origInvMat); if (mossLinearTransform(ntmp, nin, bkg, mat, msp, min[0], max[0], min[1], max[1], size[0], size[1])) { fprintf(stderr, "%s: problem doing transform:\n%s\n", me, errS = biffGetDone(MOSS)); free(errS); airMopError(mop); return 1; } if (!ai) { if (!E) E |= nrrdCopy(nacc, ntmp); } else { if (!E) E |= nrrdArithBinaryOp(nacc, nrrdBinaryOpAdd, nacc, ntmp); } if (E) { break; } } fprintf(stderr, "\n"); nrrdIterSetNrrd(itA, nacc); nrrdIterSetValue(itB, avgNum); if (!E) E |= nrrdArithIterBinaryOp(nout, nrrdBinaryOpDivide, itA, itB); if (E) { fprintf(stderr, "%s: problem making output:\n%s\n", me, errS = biffGetDone(NRRD)); free(errS); airMopError(mop); return 1; } } else { if (mossLinearTransform(nout, nin, bkg, mat, msp, min[0], max[0], min[1], max[1], size[0], size[1])) { fprintf(stderr, "%s: problem doing transform:\n%s\n", me, errS = biffGetDone(MOSS)); free(errS); airMopError(mop); return 1; } } if (nrrdSave(outS, nout, NULL)) { fprintf(stderr, "%s: problem saving output:\n%s\n", me, errS = biffGetDone(NRRD)); free(errS); airMopError(mop); return 1; } airMopOkay(mop); exit(0); }