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) 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 
29 #include <stdio.h>
30 #include <iostream>
31 #include <CMD/CMD_Args.h>
32 #include <UT/UT_Assert.h>
33 #include <UT/UT_Exit.h>
34 #include <UT/UT_Main.h>
35 #include <GU/GU_Detail.h>
36 #include <GU/GU_PrimVolume.h>
37 
38 static void
39 usage(const char *program)
40 {
41  std::cerr << "Usage: " << program << "\n";
42 }
43 
44 static inline float
45 sphereVal(int i, int j, int k, int xres, int yres, int zres)
46 {
47  float x, y, z;
48 
49  x = 2.0F * (i-0.5F*xres+0.5F) / xres;
50  y = 2.0F * (j-0.5F*yres+0.5F) / yres;
51  z = 2.0F * (k-0.5F*zres+0.5F) / zres;
52  return SYSsqrt(x*x + y*y + z*z) < 1.0F ? 1.0F : 0;
53 }
54 
55 // Generate a volume primitive with a resolution of 16x16x16. The volume
56 // primitive will be dumped as binary output to standard output.
57 //
58 // Build using:
59 // hcustom -s gengeovolume.C
60 //
61 // Example usage:
62 // gengeovolume > volume.bgeo
63 int
64 theMain(int argc, char *argv[])
65 {
66  CMD_Args args;
67  GU_Detail gdp;
68  GU_PrimVolume *volume;
69  const int xres = 16;
70  const int yres = 16;
71  const int zres = 16;
72  const int binary = 1;
73  int i, j, k;
74 
75  args.initialize(argc, argv);
76 
77  if (args.argc() != 1)
78  {
79  usage(argv[0]);
80  return 1;
81  }
82 
83  volume = (GU_PrimVolume *)GU_PrimVolume::build(&gdp);
84 
85  // The COW handle will write data to the voxel array on destruction
86  {
88 
89  handle->size(xres, yres, zres);
90  for (i = 0; i < xres; i++)
91  for (j = 0; j < yres; j++)
92  for (k = 0; k < zres; k++)
93  handle->setValue(i, j, k,
94  sphereVal(i, j, k, xres, yres, zres));
95  }
96 
97  // Can't be seekable because size unknown, do not write index
98  gdp.save(std::cout, binary, NULL);
99 
100  return 0;
101 }
102 UT_MAIN(theMain);// exit with proper tear down
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
GLint y
Definition: glcorearb.h:103
UT_MAIN(theMain)
int argc() const
Definition: UT_Args.h:48
IOStatus save(const char *filename, const GA_SaveOptions *options, UT_StringArray *errors=0) const
GLint GLenum GLint x
Definition: glcorearb.h:409
static GEO_PrimVolume * build(GU_Detail *gdp, bool integers=false, int comps=1)
GLint j
Definition: glad.h:2733
GLsizeiptr const void GLenum usage
Definition: glcorearb.h:664
int theMain(int argc, char *argv[])
Definition: gengeovolume.C:64
**If you just want to fire and args
Definition: thread.h:609
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:1931