00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdio.h>
00029 #include <iostream>
00030 #include <IMG/IMG_DeepShadow.h>
00031 #include <UT/UT_Exit.h>
00032 #include <UT/UT_Options.h>
00033 #include <UT/UT_WorkBuffer.h>
00034
00035 namespace HDK_Sample {
00036
00037 static void
00038 usage(const char *program)
00039 {
00040 cerr << "Usage: " << program << " dsmfile" << endl;
00041 cerr << "Prints out information about a deep camera/shadow image" << endl;
00042 UT_Exit::exit( UT_Exit::EXIT_GENERIC_ERROR );
00043 }
00044
00045 template <typename FTYPE> static void
00046 printTuple(const FTYPE *pixel, int vsize)
00047 {
00048 int i;
00049 printf("(%g", pixel[0]);
00050 for (i = 1; i < vsize; i++)
00051 printf(",%g", pixel[i]);
00052 printf(")");
00053 }
00054
00055 static void
00056 printPixel(IMG_DeepShadow &fp, int x, int y)
00057 {
00058 int i, d, depth;
00059 const IMG_DeepShadowChannel *chp;
00060 IMG_DeepPixelReader pixel(fp);
00061
00062
00063 if (!pixel.open(x, y))
00064 {
00065 printf("\tUnable to open pixel [%d,%d]!\n", x, y);
00066 return;
00067 }
00068
00069
00070 depth = pixel.getDepth();
00071 printf("Pixel[%d,%d][%d]\n", x, y, depth);
00072
00073
00074 for (i = 0; i < fp.getChannelCount(); i++)
00075 {
00076 chp = fp.getChannel(i);
00077 printf(" %5s = [", chp->getName());
00078 if (depth)
00079 {
00080
00081 printTuple<fpreal>(pixel.getData(*chp, 0), chp->getTupleSize());
00082
00083 for (d = 1; d < depth; d++)
00084 {
00085 printf(", ");
00086 printTuple<fpreal>(pixel.getData(*chp, d), chp->getTupleSize());
00087 }
00088 }
00089 printf("]\n");
00090 }
00091 }
00092
00093 static void
00094 dumpOptions(IMG_DeepShadow &fp)
00095 {
00096 const UT_Options *opt;
00097 UT_WorkBuffer wbuf;
00098 if (opt = fp.getTBFOptions())
00099 {
00100 wbuf.strcpy("DSM Options: ");
00101 opt->appendPyDictionary(wbuf);
00102 printf("%s\n", wbuf.buffer());
00103 }
00104 }
00105
00106 }
00107 using namespace HDK_Sample;
00108
00109 int
00110 main(int argc, char *argv[])
00111 {
00112 IMG_DeepShadow fp;
00113 int xres, yres;
00114
00115 if (!fp.open(argv[1]))
00116 usage(argv[0]);
00117
00118
00119 dumpOptions(fp);
00120
00121
00122 fp.resolution(xres, yres);
00123 printf("%s[%d,%d] (%d channels)\n",
00124 argv[1], xres, yres, fp.getChannelCount());
00125
00126
00127 printPixel(fp, 0, 0);
00128 printPixel(fp, xres>>1, 0);
00129 printPixel(fp, xres-1, 0);
00130 printPixel(fp, 0, yres>>1);
00131 printPixel(fp, xres>>1, yres>>1);
00132 printPixel(fp, xres-1, yres>>1);
00133 printPixel(fp, 0, yres-1);
00134 printPixel(fp, xres>>1, yres-1);
00135 printPixel(fp, xres-1, yres-1);
00136
00137 return 0;
00138 }