/* ** so that you can see if a given volume will work as the given kind */ int gageKindVolumeCheck(const gageKind *kind, const Nrrd *nrrd) { static const char me[]="gageKindVolumeCheck"; if (!(kind && nrrd)) { biffAddf(GAGE, "%s: got NULL pointer", me); return 1; } if (nrrdCheck(nrrd)) { biffMovef(GAGE, NRRD, "%s: problem with nrrd", me); return 1; } if (!(nrrd->dim == 3 + kind->baseDim)) { biffAddf(GAGE, "%s: nrrd should be %u-D, not %u-D", me, 3 + kind->baseDim, nrrd->dim); return 1; } if (nrrdTypeBlock == nrrd->type) { biffAddf(GAGE, "%s: can't handle %s-type volumes", me, airEnumStr(nrrdType, nrrdTypeBlock)); return 1; } if (kind->baseDim) { char stmp[AIR_STRLEN_SMALL]; if (1 == kind->baseDim) { if (kind->valLen != nrrd->axis[0].size) { biffAddf(GAGE, "%s: %s kind needs %u axis 0 values, not %s", me, kind->name, kind->valLen, airSprintSize_t(stmp, nrrd->axis[0].size)); return 1; } } else { /* actually there is yet to be a kind in Teem for which kind->baseDim > 1, but this code would work in that case */ unsigned int axi; size_t numsub; /* number of samples sub base dim */ numsub = 1; for (axi=0; axi<kind->baseDim; axi++) { numsub *= nrrd->axis[axi].size; } if (kind->valLen != numsub) { biffAddf(GAGE, "%s: %s kind needs %u values below baseDim axis %u, " "not %s", me, kind->name,kind->valLen, kind->baseDim, airSprintSize_t(stmp, numsub)); return 1; } } } /* this eventually calls _gageShapeSet(), which, for purely historical reasons, does the brunt of the error checking, some of which is almost certainly redundant with checks above . . . */ if (gageVolumeCheck(NULL, nrrd, kind)) { biffAddf(GAGE, "%s: trouble", me); return 1; } return 0; }
/* ******** gagePerVolumeNew() ** ** creates a new pervolume of a known kind, but nothing besides the ** answer array is allocated ** ** uses biff primarily because of the error checking in gageVolumeCheck() */ gagePerVolume * gagePerVolumeNew(gageContext *ctx, const Nrrd *nin, const gageKind *kind) { char me[]="gagePerVolumeNew", err[BIFF_STRLEN]; gagePerVolume *pvl; int ii; if (!( nin && kind )) { sprintf(err, "%s: got NULL pointer", me); return NULL; } if (gageVolumeCheck(ctx, nin, kind)) { sprintf(err, "%s: problem with given volume", me); biffAdd(GAGE, err); return NULL; } pvl = (gagePerVolume *)calloc(1, sizeof(gagePerVolume)); if (!pvl) { sprintf(err, "%s: couldn't alloc gagePerVolume", me); biffAdd(GAGE, err); return NULL; } pvl->verbose = gageDefVerbose; pvl->kind = kind; GAGE_QUERY_RESET(pvl->query); pvl->needD[0] = pvl->needD[1] = pvl->needD[2] = AIR_FALSE; pvl->nin = nin; for (ii=gagePvlFlagUnknown+1; ii<gagePvlFlagLast; ii++) { pvl->flag[ii] = AIR_FALSE; } pvl->iv3 = pvl->iv2 = pvl->iv1 = NULL; pvl->lup = nrrdDLookup[nin->type]; pvl->answer = (double *)calloc(gageKindTotalAnswerLength(kind), sizeof(double)); pvl->directAnswer = (double **)calloc(kind->itemMax+1, sizeof(double*)); if (!(pvl->answer && pvl->directAnswer)) { sprintf(err, "%s: couldn't alloc answer and directAnswer arrays", me); biffAdd(GAGE, err); return NULL; } for (ii=1; ii<=kind->itemMax; ii++) { pvl->directAnswer[ii] = pvl->answer + gageKindAnswerOffset(kind, ii); } pvl->flag[gagePvlFlagVolume] = AIR_TRUE; if (kind->pvlDataNew) { if (!(pvl->data = kind->pvlDataNew(kind))) { sprintf(err, "%s: double creating gagePerVolume data", me); biffAdd(GAGE, err); return NULL; } } else { pvl->data = NULL; } return pvl; }
/* ** so that you can see if a given volume will work as the given kind */ int gageKindVolumeCheck(const gageKind *kind, const Nrrd *nrrd) { static const char me[]="gageKindVolumeCheck"; if (!(kind && nrrd)) { biffAddf(GAGE, "%s: got NULL pointer", me); return 1; } if (nrrdCheck(nrrd)) { biffMovef(GAGE, NRRD, "%s: problem with nrrd", me); return 1; } if (!(nrrd->dim == 3 + kind->baseDim)) { biffAddf(GAGE, "%s: nrrd should be %u-D, not %u-D", me, 3 + kind->baseDim, nrrd->dim); return 1; } if (nrrdTypeBlock == nrrd->type) { biffAddf(GAGE, "%s: can't handle %s-type volumes", me, airEnumStr(nrrdType, nrrdTypeBlock)); return 1; } if (1 == kind->baseDim && (kind->valLen != nrrd->axis[0].size)) { biffAddf(GAGE, "%s: kind requires %u axis 0 values, not " _AIR_SIZE_T_CNV, me, kind->valLen, nrrd->axis[0].size); return 1; } /* this eventually calls _gageShapeSet(), which, for purely historical reasons, does the brunt of the error checking, some of which is almost certainly redundant with checks above ... */ if (gageVolumeCheck(NULL, nrrd, kind)) { biffAddf(GAGE, "%s: trouble", me); return 1; } return 0; }
int _miteUserCheck(miteUser *muu) { char me[]="miteUserCheck", err[BIFF_STRLEN]; int T, gotOpac; gageItemSpec isp; gageQuery queryScl, queryVec, queryTen, queryMite; miteShadeSpec *shpec; airArray *mop; unsigned int axi; if (!muu) { sprintf(err, "%s: got NULL pointer", me); biffAdd(MITE, err); return 1; } mop = airMopNew(); if (!( muu->ntxfNum >= 1 )) { sprintf(err, "%s: need at least one transfer function", me); biffAdd(MITE, err); airMopError(mop); return 1; } gotOpac = AIR_FALSE; GAGE_QUERY_RESET(queryScl); GAGE_QUERY_RESET(queryVec); GAGE_QUERY_RESET(queryTen); GAGE_QUERY_RESET(queryMite); /* not actually used here */ /* add on all queries associated with transfer functions */ for (T=0; T<muu->ntxfNum; T++) { if (miteNtxfCheck(muu->ntxf[T])) { sprintf(err, "%s: ntxf[%d] (%d of %d) can't be used as a txf", me, T, T+1, muu->ntxfNum); biffAdd(MITE, err); airMopError(mop); return 1; } /* NOTE: no error checking because miteNtxfCheck succeeded */ for (axi=1; axi<muu->ntxf[T]->dim; axi++) { miteVariableParse(&isp, muu->ntxf[T]->axis[axi].label); miteQueryAdd(queryScl, queryVec, queryTen, queryMite, &isp); } gotOpac |= !!strchr(muu->ntxf[T]->axis[0].label, 'A'); } if (!gotOpac) { fprintf(stderr, "\n\n%s: ****************************************" "************************\n", me); fprintf(stderr, "%s: !!! WARNING !!! opacity (\"A\") not set " "by any transfer function\n", me); fprintf(stderr, "%s: ****************************************" "************************\n\n\n", me); } /* add on "normal"-based queries */ if (airStrlen(muu->normalStr)) { miteVariableParse(&isp, muu->normalStr); if (miteValGageKind == isp.kind) { sprintf(err, "%s: normalStr \"%s\" refers to a miteVal " "(normal must be data-intrinsic)", me, muu->normalStr); biffAdd(MITE, err); airMopError(mop); return 1; } if (3 != isp.kind->table[isp.item].answerLength) { sprintf(err, "%s: %s not a vector: can't be used as normal", me, muu->normalStr); biffAdd(MITE, err); return 1; } miteQueryAdd(queryScl, queryVec, queryTen, queryMite, &isp); } /* add on shading-based queries */ shpec = miteShadeSpecNew(); airMopAdd(mop, shpec, (airMopper)miteShadeSpecNix, airMopAlways); if (miteShadeSpecParse(shpec, muu->shadeStr)) { sprintf(err, "%s: couldn't parse shading spec \"%s\"", me, muu->shadeStr); biffAdd(MITE, err); airMopError(mop); return 1; } miteShadeSpecQueryAdd(queryScl, queryVec, queryTen, queryMite, shpec); /* see if anyone asked for an unspecified normal */ if ((GAGE_QUERY_ITEM_TEST(queryMite, miteValNdotV) || GAGE_QUERY_ITEM_TEST(queryMite, miteValNdotL) || GAGE_QUERY_ITEM_TEST(queryMite, miteValVrefN)) && !airStrlen(muu->normalStr)) { sprintf(err, "%s: txf or shading requested a miteVal's use of the " "\"normal\", but one has not been specified in muu->normalStr", me); biffAdd(MITE, err); airMopError(mop); return 1; } /* see if we have volumes for requested queries */ if (GAGE_QUERY_NONZERO(queryScl) && !(muu->nsin)) { sprintf(err, "%s: txf or shading require %s volume, but don't have one", me, gageKindScl->name); biffAdd(MITE, err); airMopError(mop); return 1; } if (GAGE_QUERY_NONZERO(queryVec) && !(muu->nvin)) { sprintf(err, "%s: txf or shading require %s volume, but don't have one", me, gageKindVec->name); biffAdd(MITE, err); airMopError(mop); return 1; } if (GAGE_QUERY_NONZERO(queryTen) && !(muu->ntin)) { sprintf(err, "%s: txf or shading require %s volume, but don't have one", me, tenGageKind->name); biffAdd(MITE, err); airMopError(mop); return 1; } /* check appropriateness of given volumes */ if (muu->nsin) { if (gageVolumeCheck(muu->gctx0, muu->nsin, gageKindScl)) { sprintf(err, "%s: trouble with input %s volume", me, gageKindScl->name); biffMove(MITE, err, GAGE); airMopError(mop); return 1; } } if (muu->nvin) { if (gageVolumeCheck(muu->gctx0, muu->nvin, gageKindVec)) { sprintf(err, "%s: trouble with input %s volume", me, gageKindVec->name); biffMove(MITE, err, GAGE); airMopError(mop); return 1; } } if (muu->ntin) { if (gageVolumeCheck(muu->gctx0, muu->ntin, tenGageKind)) { sprintf(err, "%s: trouble with input %s volume", me, tenGageKind->name); biffMove(MITE, err, GAGE); airMopError(mop); return 1; } } if (!muu->nout) { sprintf(err, "%s: rendered image nrrd is NULL", me); biffAdd(MITE, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }