HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
i3dsphere.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 <IMG3D/IMG3D_Manager.h>
31 #include <UT/UT_Vector3.h>
32 #include <UT/UT_BoundingBox.h>
33 #include <UT/UT_Exit.h>
34 #include <UT/UT_Options.h>
35 
36 namespace HDK_Sample {
37 
38 static void
39 error(const char *msg)
40 {
41  fprintf(stderr, "Error: %s\n", msg);
43 }
44 
45 static void
46 i3dSphere(int nvalues,
47  const UT_Vector3 *P,
48  fpreal32 *result[],
49  const char *names[],
50  int sizes[],
51  int for_aa)
52 {
53  fpreal32 *density;
54  fpreal32 *color;
55  int i;
56  fpreal d;
57 
58  // Verify correct channels
59  UT_ASSERT(!strcmp(names[0], "density") && sizes[0] == 1);
60  UT_ASSERT(!strcmp(names[1], "color") && sizes[1] == 3);
61  density = result[0];
62  color = result[1];
63 
64  for (i = 0; i < nvalues; i++)
65  {
66  // Density is 1 inside the sphere and 0 outside
67  d = P[i].length() > 1 ? 0 : 1;
68  *density = d;
69  color[0] = d * SYSfit(P[i].x(), -1, 1, 0, 1);
70  color[1] = d * SYSfit(P[i].y(), -1, 1, 0, 1);
71  color[2] = d * SYSfit(P[i].z(), -1, 1, 0, 1);
72 
73  // Now, move the result buffers to the next pixel
74  density += 1; // Skip to the next float
75  color += 3; // Skip three floats
76  }
77 }
78 
79 } // End of HDK_Sample namespace
80 
81 using namespace HDK_Sample;
82 
83 int
84 main(int argc, char *argv[])
85 {
87  UT_BoundingBox bounds;
88  const char *chnames[2] = { "density", "color" };
89  int chsizes[2] = { 1, 3 };
90 
91  printf("Generating sphere.i3d\n");
92  bounds.initBounds(-1, -1, -1);
93  bounds.enlargeBounds(1, 1, 1);
94  if (!fp.createTexture("sphere.i3d", bounds, 10, 10, 10))
95  error("Unable to createTexture()");
96 
97  if (!fp.fillTexture(2, chnames, chsizes, i3dSphere, 1))
98  error("Unable to fill the texture");
99 
100  if (!fp.exportTag("software", "hdk_isosphere"))
101  error("Unable to save software tag");
102 
103  if (!fp.closeTexture())
104  error("Unable to close texture");
105 
106  return 0;
107 }
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2620
int fillTexture(int num_channels, const char *channel_names[], int channel_sizes[], IMG3D_TextureEval evaluator, int max_samples=4, fpreal variance=0.005, fpreal filter_width=1, fpreal jitter=1)
int closeTexture()
GLuint color
Definition: glcorearb.h:1260
int main(int argc, char *argv[])
Definition: i3dsphere.C:84
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
GLint y
Definition: glcorearb.h:102
static void exit(UT_ExitCode exit_code=EXIT_OK)
Calls exit(), which implicitly leads to our callbacks being called.
png_uint_32 i
Definition: png.h:2877
catch-all error code
Definition: UT_Exit.h:42
bool exportTag(const char *name, int value)
png_FILE_p fp
Definition: png.h:2028
void enlargeBounds(const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
double fpreal
Definition: SYS_Types.h:270
int createTexture(const char *filename, const UT_BoundingBox &box, int xres, int yres, int zres, int compression=5)
GLint GLenum GLint x
Definition: glcorearb.h:408
SYS_FORCE_INLINE void initBounds()
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:126
Class to handle reading/writing 3D texture images.
Definition: IMG3D_Manager.h:68
SYS_FORCE_INLINE Storage::MathFloat length() const
float fpreal32
Definition: SYS_Types.h:191