HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dsmprint.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 #include <stdio.h>
29 #include <iostream>
30 #include <IMG/IMG_DeepShadow.h>
31 #include <UT/UT_Exit.h>
32 #include <UT/UT_Options.h>
33 #include <UT/UT_WorkBuffer.h>
34 
35 namespace HDK_Sample {
36 
37 static void
38 usage(const char *program)
39 {
40  std::cerr << "Usage: " << program << " dsmfile\n";
41  std::cerr << "Prints out information about a deep camera/shadow image\n";
43 }
44 
45 template <typename FTYPE> static void
46 printTuple(const FTYPE *pixel, int vsize)
47 {
48  int i;
49  printf("(%g", pixel[0]);
50  for (i = 1; i < vsize; i++)
51  printf(",%g", pixel[i]);
52  printf(")");
53 }
54 
55 static void
56 printPixel(IMG_DeepShadow &fp, int x, int y)
57 {
58  int i, d, depth;
59  const IMG_DeepShadowChannel *chp;
60  IMG_DeepPixelReader pixel(fp);
61 
62  // Open the pixel
63  if (!pixel.open(x, y))
64  {
65  printf("\tUnable to open pixel [%d,%d]!\n", x, y);
66  return;
67  }
68 
69  // Get the number of z-records for the pixel
70  depth = pixel.getDepth();
71  printf("Pixel[%d,%d][%d]\n", x, y, depth);
72 
73  // Iterate over all channels in the DCM
74  for (i = 0; i < fp.getChannelCount(); i++)
75  {
76  chp = fp.getChannel(i);
77  printf(" %5s = [", chp->getName());
78  if (depth)
79  {
80  // Print first depth record
81  printTuple<float>(pixel.getData(*chp, 0), chp->getTupleSize());
82  // And the remaining depth records
83  for (d = 1; d < depth; d++)
84  {
85  printf(", ");
86  printTuple<float>(pixel.getData(*chp, d), chp->getTupleSize());
87  }
88  }
89  printf("]\n");
90  }
91 }
92 
93 static void
94 dumpOptions(IMG_DeepShadow &fp)
95 {
97  UT_WorkBuffer wbuf;
98  opt = fp.getTextureOptions();
99  if (opt)
100  {
101  wbuf.strcpy("DSM Options: ");
102  opt->appendPyDictionary(wbuf);
103  printf("%s\n", wbuf.buffer());
104  }
105 }
106 
107 }
108 using namespace HDK_Sample;
109 
110 int
111 main(int argc, char *argv[])
112 {
114  int xres, yres;
115 
116  if (!fp.open(argv[1]))
117  usage(argv[0]);
118 
119  // Read the texture options in the file
120  dumpOptions(fp);
121 
122  // Query the resolution
123  fp.resolution(xres, yres);
124  printf("%s[%d,%d] (%d channels)\n",
125  argv[1], xres, yres, fp.getChannelCount());
126 
127  // Print the raw pixel data
128  printPixel(fp, 0, 0);
129  printPixel(fp, xres>>1, 0);
130  printPixel(fp, xres-1, 0);
131  printPixel(fp, 0, yres>>1);
132  printPixel(fp, xres>>1, yres>>1);
133  printPixel(fp, xres-1, yres>>1);
134  printPixel(fp, 0, yres-1);
135  printPixel(fp, xres>>1, yres-1);
136  printPixel(fp, xres-1, yres-1);
137 
138  return 0;
139 }
void resolution(int &xres, int &yres) const
Get the resolution of the deep shadow map.
Thread-safe convenience class to make reading DSM pixels easy.
void strcpy(const char *src)
Single channel of a Houdini DSM image.
GLint y
Definition: glcorearb.h:102
Class to read or write deep shadow/camera images.
const IMG_DeepShadowChannel * getChannel(int i) const
Get a channel definition.
static void exit(UT_ExitCode exit_code=EXIT_OK)
Calls exit(), which implicitly leads to our callbacks being called.
UT_SharedPtr< UT_Options > getTextureOptions() const
png_uint_32 i
Definition: png.h:2877
catch-all error code
Definition: UT_Exit.h:42
png_FILE_p fp
Definition: png.h:2028
const char * getName() const
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:475
int getTupleSize() const
int main(int argc, char *argv[])
Definition: dsmprint.C:111
bool open(const char *name)
Open a deep shadow map for reading.
int getChannelCount() const
Get the number of channels in the DSM.
GLsizeiptr const void GLenum usage
Definition: glcorearb.h:663
GLint GLenum GLint x
Definition: glcorearb.h:408
const char * buffer() const
GLbitfield GLuint program
Definition: glcorearb.h:1930