HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dsmprint.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
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_Main.h>
33 #include <UT/UT_Options.h>
34 #include <UT/UT_WorkBuffer.h>
35 
36 namespace HDK_Sample {
37 
38 static void
39 usage(const char *program)
40 {
41  std::cerr << "Usage: " << program << " dsmfile\n";
42  std::cerr << "Prints out information about a deep camera/shadow image\n";
44 }
45 
46 template <typename FTYPE> static void
47 printTuple(const FTYPE *pixel, int vsize)
48 {
49  int i;
50  printf("(%g", pixel[0]);
51  for (i = 1; i < vsize; i++)
52  printf(",%g", pixel[i]);
53  printf(")");
54 }
55 
56 static void
57 printPixel(IMG_DeepShadow &fp, int x, int y)
58 {
59  int i, d, depth;
60  const IMG_DeepShadowChannel *chp;
61  IMG_DeepPixelReader pixel(fp);
62 
63  // Open the pixel
64  if (!pixel.open(x, y))
65  {
66  printf("\tUnable to open pixel [%d,%d]!\n", x, y);
67  return;
68  }
69 
70  // Get the number of z-records for the pixel
71  depth = pixel.getDepth();
72  printf("Pixel[%d,%d][%d]\n", x, y, depth);
73 
74  // Iterate over all channels in the DCM
75  for (i = 0; i < fp.getChannelCount(); i++)
76  {
77  chp = fp.getChannel(i);
78  printf(" %5s = [", chp->getName());
79  if (depth)
80  {
81  // Print first depth record
82  printTuple<float>(pixel.getData(*chp, 0), chp->getTupleSize());
83  // And the remaining depth records
84  for (d = 1; d < depth; d++)
85  {
86  printf(", ");
87  printTuple<float>(pixel.getData(*chp, d), chp->getTupleSize());
88  }
89  }
90  printf("]\n");
91  }
92 }
93 
94 static void
95 dumpOptions(IMG_DeepShadow &fp)
96 {
98  UT_WorkBuffer wbuf;
99  opt = fp.getTextureOptions();
100  if (opt)
101  {
102  wbuf.strcpy("DSM Options: ");
103  opt->appendPyDictionary(wbuf);
104  printf("%s\n", wbuf.buffer());
105  }
106 }
107 
108 }
109 using namespace HDK_Sample;
110 
111 int
112 theMain(int argc, char *argv[])
113 {
114  IMG_DeepShadow fp;
115  int xres, yres;
116 
117  if (!fp.open(argv[1]))
118  usage(argv[0]);
119 
120  // Read the texture options in the file
121  dumpOptions(fp);
122 
123  // Query the resolution
124  fp.resolution(xres, yres);
125  printf("%s[%d,%d] (%d channels)\n",
126  argv[1], xres, yres, fp.getChannelCount());
127 
128  // Print the raw pixel data
129  printPixel(fp, 0, 0);
130  printPixel(fp, xres>>1, 0);
131  printPixel(fp, xres-1, 0);
132  printPixel(fp, 0, yres>>1);
133  printPixel(fp, xres>>1, yres>>1);
134  printPixel(fp, xres-1, yres>>1);
135  printPixel(fp, 0, yres-1);
136  printPixel(fp, xres>>1, yres-1);
137  printPixel(fp, xres-1, yres-1);
138 
139  return 0;
140 }
141 UT_MAIN(theMain);// exit with proper tear down
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.
auto printf(const S &fmt, const T &...args) -> int
Definition: printf.h:626
Single channel of a Houdini DSM image.
SYS_FORCE_INLINE const char * buffer() const
SYS_FORCE_INLINE void strcpy(const char *src)
GLint y
Definition: glcorearb.h:103
Class to read or write deep shadow/camera images.
const IMG_DeepShadowChannel * getChannel(int i) const
Get a channel definition.
UT_SharedPtr< UT_Options > getTextureOptions() const
catch-all error code
Definition: UT_Exit.h:42
static SYS_FUNC_NORETURN void exit(UT_ExitCode exit_code=EXIT_OK)
Calls exit(), which implicitly leads to our callbacks being called.
const char * getName() const
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
int getTupleSize() const
int theMain(int argc, char *argv[])
Definition: dsmprint.C:112
GLint GLenum GLint x
Definition: glcorearb.h:409
bool open(const char *name)
Open a deep shadow map for reading.
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
int getChannelCount() const
Get the number of channels in the DSM.
GLsizeiptr const void GLenum usage
Definition: glcorearb.h:664
UT_MAIN(theMain)
GLbitfield GLuint program
Definition: glcorearb.h:1931