HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gengeovolume.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 
29 #include <stdio.h>
30 #include <iostream>
31 #include <CMD/CMD_Args.h>
32 #include <UT/UT_Assert.h>
33 #include <GU/GU_Detail.h>
34 #include <GU/GU_PrimVolume.h>
35 
36 static void
37 usage(const char *program)
38 {
39  std::cerr << "Usage: " << program << "\n";
40 }
41 
42 static inline float
43 sphereVal(int i, int j, int k, int xres, int yres, int zres)
44 {
45  float x, y, z;
46 
47  x = 2.0F * (i-0.5F*xres+0.5F) / xres;
48  y = 2.0F * (j-0.5F*yres+0.5F) / yres;
49  z = 2.0F * (k-0.5F*zres+0.5F) / zres;
50  return SYSsqrt(x*x + y*y + z*z) < 1.0F ? 1.0F : 0;
51 }
52 
53 // Generate a volume primitive with a resolution of 16x16x16. The volume
54 // primitive will be dumped as binary output to standard output.
55 //
56 // Build using:
57 // hcustom -s gengeovolume.C
58 //
59 // Example usage:
60 // gengeovolume > volume.bgeo
61 int
62 main(int argc, char *argv[])
63 {
64  CMD_Args args;
65  GU_Detail gdp;
66  GU_PrimVolume *volume;
67  const int xres = 16;
68  const int yres = 16;
69  const int zres = 16;
70  const int binary = 1;
71  int i, j, k;
72 
73  args.initialize(argc, argv);
74 
75  if (args.argc() != 1)
76  {
77  usage(argv[0]);
78  return 1;
79  }
80 
81  volume = (GU_PrimVolume *)GU_PrimVolume::build(&gdp);
82 
83  // The COW handle will write data to the voxel array on destruction
84  {
86 
87  handle->size(xres, yres, zres);
88  for (i = 0; i < xres; i++)
89  for (j = 0; j < yres; j++)
90  for (k = 0; k < zres; k++)
91  handle->setValue(i, j, k,
92  sphereVal(i, j, k, xres, yres, zres));
93  }
94 
95  // Can't be seekable because size unknown, do not write index
96  gdp.save(std::cout, binary, NULL);
97  return 0;
98 }
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
int main(int argc, char *argv[])
Definition: gengeovolume.C:62
GLint y
Definition: glcorearb.h:102
png_uint_32 i
Definition: png.h:2877
static GEO_PrimVolume * build(GU_Detail *gdp)
int argc() const
Definition: UT_Args.h:43
IOStatus save(const char *filename, const GA_SaveOptions *options, UT_StringArray *errors=0) const
GLsizeiptr const void GLenum usage
Definition: glcorearb.h:663
GLint GLenum GLint x
Definition: glcorearb.h:408
UT_VoxelArrayWriteHandleF getVoxelWriteHandle()
This is a handle that you can write to and affect the volume.
void initialize(int argc, const char *const argv[])
GLbitfield GLuint program
Definition: glcorearb.h:1930