#include <stdio.h>
#include <iostream>
#include <IMG/IMG_DeepShadow.h>
#include <UT/UT_Exit.h>
#include <UT/UT_Options.h>
#include <UT/UT_WorkBuffer.h>
namespace HDK_Sample {
static void
usage(const char *program)
{
cerr << "Usage: " << program << " dsmfile" << endl;
cerr << "Prints out information about a deep camera/shadow image" << endl;
UT_Exit::exit( UT_Exit::EXIT_GENERIC_ERROR );
}
template <typename FTYPE> static void
printTuple(const FTYPE *pixel, int vsize)
{
int i;
printf("(%g", pixel[0]);
for (i = 1; i < vsize; i++)
printf(",%g", pixel[i]);
printf(")");
}
static void
printPixel(IMG_DeepShadow &fp, int x, int y)
{
int i, d, depth;
const IMG_DeepShadowChannel *chp;
IMG_DeepPixelReader pixel(fp);
if (!pixel.open(x, y))
{
printf("\tUnable to open pixel [%d,%d]!\n", x, y);
return;
}
depth = pixel.getDepth();
printf("Pixel[%d,%d][%d]\n", x, y, depth);
for (i = 0; i < fp.getChannelCount(); i++)
{
chp = fp.getChannel(i);
printf(" %5s = [", chp->getName());
if (depth)
{
printTuple<float>(pixel.getData(*chp, 0), chp->getTupleSize());
for (d = 1; d < depth; d++)
{
printf(", ");
printTuple<float>(pixel.getData(*chp, d), chp->getTupleSize());
}
}
printf("]\n");
}
}
static void
dumpOptions(IMG_DeepShadow &fp)
{
const UT_Options *opt;
UT_WorkBuffer wbuf;
if (opt = fp.getTBFOptions())
{
wbuf.strcpy("DSM Options: ");
opt->appendPyDictionary(wbuf);
printf("%s\n", wbuf.buffer());
}
}
}
using namespace HDK_Sample;
int
main(int argc, char *argv[])
{
IMG_DeepShadow fp;
int xres, yres;
if (!fp.open(argv[1]))
usage(argv[0]);
dumpOptions(fp);
fp.resolution(xres, yres);
printf("%s[%d,%d] (%d channels)\n",
argv[1], xres, yres, fp.getChannelCount());
printPixel(fp, 0, 0);
printPixel(fp, xres>>1, 0);
printPixel(fp, xres-1, 0);
printPixel(fp, 0, yres>>1);
printPixel(fp, xres>>1, yres>>1);
printPixel(fp, xres-1, yres>>1);
printPixel(fp, 0, yres-1);
printPixel(fp, xres>>1, yres-1);
printPixel(fp, xres-1, yres-1);
return 0;
}