|
From: <kin...@us...> - 2004-02-26 06:49:05
|
Update of /cvsroot/teem/teem/src/mite In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15761 Added Files: shade.c kindnot.c Log Message: new to mite --- NEW FILE: shade.c --- /* teem: Gordon Kindlmann's research software Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mite.h" #include "privateMite.h" miteShadeSpec * miteShadeSpecNew(void) { miteShadeSpec *shpec; shpec = (miteShadeSpec *)calloc(1, sizeof(miteShadeSpec)); if (shpec) { shpec->method = miteShadeMethodUnknown; shpec->vec0 = gageItemSpecNew(); shpec->vec1 = gageItemSpecNew(); shpec->scl0 = gageItemSpecNew(); shpec->scl1 = gageItemSpecNew(); if (!( shpec->vec0 && shpec->vec1 && shpec->scl0 && shpec->scl1 )) { return NULL; } } return shpec; } miteShadeSpec * miteShadeSpecNix(miteShadeSpec *shpec) { if (shpec) { shpec->vec0 = gageItemSpecNix(shpec->vec0); shpec->vec1 = gageItemSpecNix(shpec->vec1); shpec->scl0 = gageItemSpecNix(shpec->scl0); shpec->scl1 = gageItemSpecNix(shpec->scl1); AIR_FREE(shpec); } return NULL; } /* ******** miteShadeSpecParse ** ** set up a miteShadeSpec based on a string. Valid forms are: ** ** none ** phong:<vector> ** litten:<vector>,<vector>,<scalar>,<scalar> ** ** where <vector> and <scalar> are specifications of 3-vector and scalar ** parsable by miteVariableParse */ int miteShadeSpecParse(miteShadeSpec *shpec, char *shadeStr) { char me[]="miteShadeSpecParse", err[AIR_STRLEN_MED], *buff, *qstr, *tok, *state; airArray *mop; int ansLength; mop = airMopNew(); if (!( shpec && airStrlen(shadeStr) )) { sprintf(err, "%s: got NULL pointer and/or empty string", me); biffAdd(MITE, err); airMopError(mop); return 1; } buff = airToLower(airStrdup(shadeStr)); if (!buff) { sprintf(err, "%s: couldn't strdup shading spec", me); biffAdd(MITE, err); airMopError(mop); return 1; } airMopAdd(mop, buff, airFree, airMopAlways); shpec->method = miteShadeMethodUnknown; if (!strcmp("none", buff)) { shpec->method = miteShadeMethodNone; } else if (buff == strstr(buff, "phong:")) { shpec->method = miteShadeMethodPhong; qstr = buff + strlen("phong:"); if (miteVariableParse(shpec->vec0, qstr)) { sprintf(err, "%s: couldn't parse \"%s\" as shading vector", me, qstr); biffAdd(MITE, err); airMopError(mop); return 1; } ansLength = shpec->vec0->kind->table[shpec->vec0->item].answerLength; if (3 != ansLength) { sprintf(err, "%s: \"%s\" isn't a vector (answer length is %d, not 3)", me, qstr, ansLength); biffAdd(MITE, err); airMopError(mop); return 1; } shpec->method = miteShadeMethodPhong; } else if (buff == strstr(buff, "litten:")) { qstr = buff + strlen("litten:"); /* ---- first vector */ tok = airStrtok(qstr, ",", &state); if (miteVariableParse(shpec->vec0, tok)) { sprintf(err, "%s: couldn't parse \"%s\" as first lit-tensor vector", me, tok); biffAdd(MITE, err); airMopError(mop); return 1; } ansLength = shpec->vec0->kind->table[shpec->vec0->item].answerLength; if (3 != ansLength) { sprintf(err, "%s: \"%s\" isn't a vector (answer length is %d, not 3)", me, qstr, ansLength); biffAdd(MITE, err); airMopError(mop); return 1; } /* ---- second vector */ tok = airStrtok(qstr, ",", &state); if (miteVariableParse(shpec->vec1, tok)) { sprintf(err, "%s: couldn't parse \"%s\" as second lit-tensor vector", me, tok); biffAdd(MITE, err); airMopError(mop); return 1; } ansLength = shpec->vec1->kind->table[shpec->vec1->item].answerLength; if (3 != ansLength) { sprintf(err, "%s: \"%s\" isn't a vector (answer length is %d, not 3)", me, qstr, ansLength); biffAdd(MITE, err); airMopError(mop); return 1; } /* ---- first scalar */ tok = airStrtok(qstr, ",", &state); if (miteVariableParse(shpec->scl0, tok)) { sprintf(err, "%s: couldn't parse \"%s\" as first lit-tensor scalar", me, tok); biffAdd(MITE, err); airMopError(mop); return 1; } ansLength = shpec->scl0->kind->table[shpec->scl0->item].answerLength; if (1 != ansLength) { sprintf(err, "%s: \"%s\" isn't a scalar (answer length is %d, not 1)", me, qstr, ansLength); biffAdd(MITE, err); airMopError(mop); return 1; } /* ---- second scalar */ tok = airStrtok(qstr, ",", &state); if (miteVariableParse(shpec->scl1, tok)) { sprintf(err, "%s: couldn't parse \"%s\" as second lit-tensor scalar", me, tok); biffAdd(MITE, err); airMopError(mop); return 1; } ansLength = shpec->scl1->kind->table[shpec->scl1->item].answerLength; if (1 != ansLength) { sprintf(err, "%s: \"%s\" isn't a scalar (answer length is %d, not 1)", me, qstr, ansLength); biffAdd(MITE, err); airMopError(mop); return 1; } shpec->method = miteShadeMethodLitTen; } else { sprintf(err, "%s: shading specification \"%s\" not understood", me, shadeStr); biffAdd(MITE, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; } void miteShadeSpecPrint(char *buff, const miteShadeSpec *shpec) { char me[]="miteShadeSpecPrint", var[4][AIR_STRLEN_MED]; if (buff && shpec) { switch(shpec->method) { case miteShadeMethodNone: sprintf(buff, "none"); break; case miteShadeMethodPhong: miteVariablePrint(var[0], shpec->vec0); sprintf(buff, "phong:%s", var[0]); break; case miteShadeMethodLitTen: miteVariablePrint(var[0], shpec->vec0); miteVariablePrint(var[1], shpec->vec1); miteVariablePrint(var[2], shpec->scl0); miteVariablePrint(var[3], shpec->scl1); sprintf(buff, "litten:%s,%s,%s,%s", var[0], var[1], var[2], var[3]); break; default: sprintf(buff, "%s: unknown shade method!", me); break; } } return; } void miteShadeSpecQueryAdd(gageQuery queryScl, gageQuery queryVec, gageQuery queryTen, miteShadeSpec *shpec) { if (shpec) { switch(shpec->method) { case miteShadeMethodNone: /* no queries to add */ break; case miteShadeMethodPhong: miteQueryAdd(queryScl, queryVec, queryTen, shpec->vec0); break; case miteShadeMethodLitTen: miteQueryAdd(queryScl, queryVec, queryTen, shpec->vec0); miteQueryAdd(queryScl, queryVec, queryTen, shpec->vec1); miteQueryAdd(queryScl, queryVec, queryTen, shpec->scl0); miteQueryAdd(queryScl, queryVec, queryTen, shpec->scl1); break; default: break; } } return; } --- NEW FILE: kindnot.c --- /* teem: Gordon Kindlmann's research software Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mite.h" #include "privateMite.h" char _miteValStr[][AIR_STRLEN_SMALL] = { "(unknown miteVal)", "Xw", "Xi", "Yw", "Yi", "Zw", "Zi", "Tw", "Ti", "NdotV", "NdotL", "GTdotV", "VrefN", "VdefT", "VdefTdotV" }; int _miteValVal[] = { miteValUnknown, miteValXw, miteValXi, miteValYw, miteValYi, miteValZw, miteValZi, miteValTw, miteValTi, miteValNdotV, miteValNdotL, miteValGTdotV, miteValVrefN, miteValVdefT, miteValVdefTdotV }; char _miteValStrEqv[][AIR_STRLEN_SMALL] = { "xw", "xi", "yw", "yi", "zw", "zi", "tw", "ti", "ndotv", "vdotn", "ndotl", "ldotn", "gtdotv", "vrefn", "vdeft", "vdeftdotv" "" }; int _miteValValEqv[] = { miteValXw, miteValXi, miteValYw, miteValYi, miteValZw, miteValZi, miteValTw, miteValTi, miteValNdotV, miteValNdotV, miteValNdotL, miteValNdotL, miteValGTdotV, miteValVrefN, miteValVdefT, miteValVdefTdotV }; airEnum _miteVal = { "miteVal", MITE_VAL_ITEM_MAX+1, _miteValStr, _miteValVal, NULL, _miteValStrEqv, _miteValValEqv, AIR_FALSE }; airEnum * miteVal = &_miteVal; /* ** again, this is not a true gageKind- mainly because these items ** depend on items in different gageKinds (scalar and vector). So, ** the prerequisites here are all blank. Go look in _miteQueryAdd() ** to see these items' true prereqs */ gageItemEntry _miteValTable[MITE_VAL_ITEM_MAX+1] = { /* enum value len,deriv, prereqs, parent item, index*/ {miteValXw, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValXi, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValYw, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValYi, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValZw, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValZi, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValTw, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValTi, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValNdotV, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValNdotL, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValGTdotV, 1, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValVrefN, 3, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValVdefT, 3, 0, {-1, -1, -1, -1, -1}, -1, -1}, {miteValVdefTdotV, 1, 0, {-1, -1, -1, -1, -1}, -1, -1} }; gageKind _miteValGageKind = { "mite", &_miteVal, -1, -1, MITE_VAL_ITEM_MAX, _miteValTable, NULL, NULL, NULL }; gageKind * miteValGageKind = &_miteValGageKind; |