decolorize callback

New Message Reply Date view Thread view Subject view Author view

Nathaniel Bletter (nat++at++od.sri.com)
Wed, 1 Feb 1995 16:14:33 -0800


I'm trying to write a pfuTraverser procedure to decolorize the current scene by
finding the color of every vertex and and setting RG and B all to the same
level. This level would be the luminance of that RGB triplet. Below is the
traverser callback to do decolorization that I've written.
        It doesn't seem to work at all. I've run the debugger on it several
times and for GeoSets made up of TRISTRIPS, it does nothing, although the
values seem to change, they have no effect on the appearance.
        For FLAT_TRI_STRIPS, the calculation for the # of colors doesn't work
and it seems to overwrite memory when it writes new values. Is the formula for
the number of colors required for a PER_VERTEX color binding on FLAT_TRI_STRIPS
# of colors = Sum(length[i]-2), i=0 to # of primitives? The man pages are a
little sketchy on this.

Thanks for the help.

void
luminance(pfVec4 source, pfVec4 dest)
{
  float lum;

  lum = source[0];
  dest[0] = dest[1] = dest[2] = lum;
}

static long
  cbDecolorize(pfuTraverser *trav)
{
  pfNode *node = trav->node;

  if (!node) {
    pfNotify(PFNFY_DEBUG, PFNFY_PRINT, "cbCountNodes: node null!");
    return PFTRAV_CONT;
  }

  if (pfGetType(node) == PFTYPE_GEODE) {
    long nGSets = pfGetNumGSets((pfGeode *)node);
    long i;
    for (i = 0 ; i < nGSets ; i++)
      {
        pfGeoSet *gd = pfGetGSet((pfGeode *)node, i);
        long nPrims = pfGetGSetNumPrims(gd);
        long *primLens = pfGetGSetPrimLengths(gd);
        long ptype = pfGetGSetPrimType(gd);
        long cbind = pfGetGSetAttrBind(gd, PFGS_COLOR4);
        long nVerts = 0;
        long k;
        ulong which = PFQGSET_NUM_VERTS;
        pfVec4 *alist;
        ushort *ilist;
        pfVec4 color;

        pfQueryGSet(gd, &which, (float *)&nVerts);

        switch (cbind) {
        case PFGS_OFF :
          break;

        case PFGS_OVERALL:
          pfGetGSetAttrLists(gd, PFGS_COLOR4, (void **)(&alist), &ilist);
          luminance(alist[0], alist[0]);
          pfGSetAttr(gd, PFGS_COLOR4, cbind, (void *)alist, ilist);
          break;

        case PFGS_PER_PRIM:
          pfGetGSetAttrLists(gd, PFGS_COLOR4, (void **)(&alist), &ilist);
          for (k=0; k<nPrims; k++) {
            if (ilist == NULL)
              luminance(alist[k], alist[k]);
            else
              luminance(alist[ilist[k]], alist[ilist[k]]);
          }
          pfGSetAttr(gd, PFGS_COLOR4, cbind, (void *)alist, ilist);
          break;

        case PFGS_PER_VERTEX:
          pfGetGSetAttrLists(gd, PFGS_COLOR4, (void **)(&alist), &ilist);
          if (ptype == PFGS_FLAT_LINESTRIPS || ptype == PFGS_FLAT_TRISTRIPS) {
            nVerts = 0;
            for (k=0; k<nPrims; k++)
              switch (ptype) {
              case PFGS_FLAT_LINESTRIPS :
                nVerts += primLens[k]-1;
                break;
              case PFGS_FLAT_TRISTRIPS :
                nVerts += primLens[k]-2;
                break;
              }
          }

          for (k=0; k<nVerts; k++) {
            if (ilist == NULL) {
              luminance(alist[k], alist[k]);
            }
            else
              luminance(alist[ilist[k]], alist[ilist[k]]);
          }
          pfGSetAttr(gd, PFGS_COLOR4, cbind, (void *)alist, ilist);
          break;
        }
      }
  }

  return PFTRAV_CONT;
}

-- 

Nat Bletter SRI International nat++at++od.sri.com (415) 859-4358


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:50:56 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.