HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RAY_DemoStamp.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  * This is a sample procedural DSO
27  */
28 
29 #include <UT/UT_DSOVersion.h>
30 #include <GU/GU_Detail.h>
31 #include "RAY_DemoStamp.h"
33 
34 // The ray_ChildBox is a "private" procedural.
35 // The user can't allocate one of these directly.
36 namespace HDK_Sample {
37 /// @brief Procedural used in @ref RAY/RAY_DemoStamp.C to render a box
38 /// @see @ref RAY/RAY_DemoBox.C
40 {
41 public:
43  : myCenter(center),
44  mySize(size)
45  {}
46  ~ray_ChildBox() override {}
47 
48  const char *className() const override
49  { return "ray_ChildBox"; }
50 
51  /// Since the procedural is generated by stamp, this
52  /// method will never be called.
53  int initialize(const UT_BoundingBox *) override
54  {
55  return 0;
56  }
57  void getBoundingBox(UT_BoundingBox &box) override
58  {
59  box.initBounds(myCenter);
60  box.expandBounds(0, mySize);
61  }
62  void render() override
63  {
65  geo->cube(
66  myCenter.x()-mySize, myCenter.x()+mySize,
67  myCenter.y()-mySize, myCenter.y()+mySize,
68  myCenter.z()-mySize, myCenter.z()+mySize);
70  child->addGeometry(geo);
71  }
72 private:
73  UT_Vector3 myCenter;
74  fpreal mySize;
75 };
76 } // End HDK_Sample namespace
77 
78 using namespace HDK_Sample;
79 
80 // Arguments for the stamp procedural
81 static RAY_ProceduralArg theArgs[] = {
82  RAY_ProceduralArg("minbound", "real", "-1 -1 -1"),
83  RAY_ProceduralArg("maxbound", "real", "1 1 1"),
84  RAY_ProceduralArg("size", "real", ".1"),
85  RAY_ProceduralArg("npoints", "int", "10"),
86  RAY_ProceduralArg("seed", "int", "1"),
88 };
89 
91 {
92 public:
94  : RAY_ProceduralFactory::ProcDefinition("demostamp")
95  {
96  }
97  RAY_Procedural *create() const override { return new RAY_DemoStamp(); }
98  RAY_ProceduralArg *arguments() const override { return theArgs; }
99 };
100 
101 void
103 {
104  factory->insert(new ProcDef);
105 }
106 
107 
109 {
110  myBox.initBounds(0, 0, 0);
111 }
112 
114 {
115 }
116 
117 const char *
119 {
120  return "RAY_DemoStamp";
121 }
122 
123 int
125 {
126  fpreal val[3];
127 
128  // Evaluate parameters and store the information
129  val[0] = val[1] = val[2] = -1;
130  import("minbound", val, 3);
131  myBox.initBounds(val[0], val[1], val[2]);
132 
133  val[0] = val[1] = val[2] = 1;
134  import("maxbound", val, 3);
135  myBox.enlargeBounds(val[0], val[1], val[2]);
136 
137  if (!import("size", &mySize, 1))
138  mySize = 0.1;
139  if (!import("npoints", &myCount, 1))
140  myCount = 10;
141  if (!import("seed", &mySeed, 1))
142  mySeed = 1;
143 
144  mySize = SYSabs(mySize);
145 
146  return 1;
147 }
148 
149 void
151 {
152  // Initialize with the bounding box of the stamp procedural
153  box = myBox;
154 
155  // Each child box can also enlarge the bounds by the size of the child
156  box.expandBounds(0, mySize);
157 }
158 
159 void
161 {
162  int i;
163  UT_Vector3 c;
164  unsigned int seed;
165  float cx, cy, cz;
166 
167  seed = mySeed;
168  for (i = 0; i < myCount; i++)
169  {
170  // Compute random numbers deterministically. If they were computed in
171  // the assign operation, compilers could compute them in a different
172  // order.
173  cx = SYSfastRandom(seed);
174  cy = SYSfastRandom(seed);
175  cz = SYSfastRandom(seed);
176  c.assign( SYSfit(cx, 0.0f, 1.0f, myBox.xmin(), myBox.xmax()),
177  SYSfit(cy, 0.0f, 1.0f, myBox.ymin(), myBox.ymax()),
178  SYSfit(cz, 0.0f, 1.0f, myBox.zmin(), myBox.zmax()) );
179 
180  // Create a new procedural object
182  // We create the procedural ourselves.
183  // Alternatively, it's also possible to create a procedural by
184  // passing arguments. This would allow the user to control which
185  // procedural gets built.
186  obj->addProcedural( new ray_ChildBox(c, mySize) );
187  }
188 }
void getBoundingBox(UT_BoundingBox &box) override
The bounding box is the "object space" bounds of the procedural.
RAY_ProceduralGeo createGeometry() const
Allocate geometry for this procedural.
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:667
Procedural primitive for mantra (RAY)
#define SYSabs(a)
Definition: SYS_Math.h:1572
bool insert(ProcDefinition *def, bool replace_existing=true)
A procedural which splits into further procedurals during rendering.
Definition: RAY_DemoStamp.h:40
SYS_FORCE_INLINE void expandBounds(T relative, T absolute)
GLfloat f
Definition: glcorearb.h:1926
void registerProcedural(RAY_ProceduralFactory *factory)
Modern interface to register procedurals.
void render() override
Definition: RAY_DemoStamp.C:62
int initialize(const UT_BoundingBox *) override
Definition: RAY_DemoStamp.C:53
void getBoundingBox(UT_BoundingBox &box) override
The bounding box is the "object space" bounds of the procedural.
Definition: RAY_DemoStamp.C:57
RAY_ProceduralChildPtr createChild() const
void enlargeBounds(const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
Procedural used in RAY/RAY_DemoStamp.C to render a box.
Definition: RAY_DemoStamp.C:39
Parameter definition for arguments to RAY_Procedural.
ray_ChildBox(UT_Vector3 &center, fpreal size)
Definition: RAY_DemoStamp.C:42
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f)
Set the values of the vector components.
Definition: UT_Vector3.h:694
GLsizeiptr size
Definition: glcorearb.h:664
fpreal64 fpreal
Definition: SYS_Types.h:277
int initialize(const UT_BoundingBox *) override
GU_PrimPoly * cube(float xmin=-1, float xmax=1, float ymin=-1, float ymax=1, float zmin=-1, float zmax=1, int xdiv=0, int ydiv=0, int zdiv=0, int enforcementBars=0, int doConsolidatePoints=0)
GLuint GLfloat * val
Definition: glcorearb.h:1608
SYS_FORCE_INLINE void initBounds()
RAY_ProceduralArg * arguments() const override
Provide a const reference to the arguments for the procedural.
Definition: RAY_DemoStamp.C:98
const char * className() const override
RAY_Procedural * create() const override
Create a procedural, and pass ownership of the instance to mantra.
Definition: RAY_DemoStamp.C:97
const char * className() const override
Definition: RAY_DemoStamp.C:48
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:665
Class to create a procedural.
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:663