HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RAY_DemoStamp.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  * 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  virtual ~ray_ChildBox() {}
47 
48  virtual const char *className() const { return "ray_ChildBox"; }
49  /// Since the procedural is generated by stamp, this
50  /// method will never be called.
51  virtual int initialize(const UT_BoundingBox *)
52  {
53  return 0;
54  }
55  virtual void getBoundingBox(UT_BoundingBox &box)
56  {
57  box.initBounds(myCenter);
58  box.expandBounds(0, mySize);
59  }
60  virtual void render()
61  {
63  geo->cube(
64  myCenter.x()-mySize, myCenter.x()+mySize,
65  myCenter.y()-mySize, myCenter.y()+mySize,
66  myCenter.z()-mySize, myCenter.z()+mySize);
68  child->addGeometry(geo);
69  }
70 private:
71  UT_Vector3 myCenter;
72  fpreal mySize;
73 };
74 } // End HDK_Sample namespace
75 
76 using namespace HDK_Sample;
77 
78 // Arguments for the stamp procedural
79 static RAY_ProceduralArg theArgs[] = {
80  RAY_ProceduralArg("minbound", "real", "-1 -1 -1"),
81  RAY_ProceduralArg("maxbound", "real", "1 1 1"),
82  RAY_ProceduralArg("size", "real", ".1"),
83  RAY_ProceduralArg("npoints", "int", "10"),
84  RAY_ProceduralArg("seed", "int", "1"),
86 };
87 
89 {
90 public:
92  : RAY_ProceduralFactory::ProcDefinition("demostamp")
93  {
94  }
95  virtual RAY_Procedural *create() const { return new RAY_DemoStamp(); }
96  virtual RAY_ProceduralArg *arguments() const { return theArgs; }
97 };
98 
99 void
101 {
102  factory->insert(new ProcDef);
103 }
104 
105 
107 {
108  myBox.initBounds(0, 0, 0);
109 }
110 
112 {
113 }
114 
115 const char *
117 {
118  return "RAY_DemoStamp";
119 }
120 
121 int
123 {
124  fpreal val[3];
125 
126  // Evaluate parameters and store the information
127  val[0] = val[1] = val[2] = -1;
128  import("minbound", val, 3);
129  myBox.initBounds(val[0], val[1], val[2]);
130 
131  val[0] = val[1] = val[2] = 1;
132  import("maxbound", val, 3);
133  myBox.enlargeBounds(val[0], val[1], val[2]);
134 
135  if (!import("size", &mySize, 1))
136  mySize = 0.1;
137  if (!import("npoints", &myCount, 1))
138  myCount = 10;
139  if (!import("seed", &mySeed, 1))
140  mySeed = 1;
141 
142  mySize = SYSabs(mySize);
143 
144  return 1;
145 }
146 
147 void
149 {
150  // Initialize with the bounding box of the stamp procedural
151  box = myBox;
152 
153  // Each child box can also enlarge the bounds by the size of the child
154  box.expandBounds(0, mySize);
155 }
156 
157 void
159 {
160  int i;
161  UT_Vector3 c;
162  unsigned int seed;
163  float cx, cy, cz;
164 
165  seed = mySeed;
166  for (i = 0; i < myCount; i++)
167  {
168  // Compute random numbers deterministically. If they were computed in
169  // the assign operation, compilers could compute them in a different
170  // order.
171  cx = SYSfastRandom(seed);
172  cy = SYSfastRandom(seed);
173  cz = SYSfastRandom(seed);
174  c.assign( SYSfit(cx, 0.0f, 1.0f, myBox.xmin(), myBox.xmax()),
175  SYSfit(cy, 0.0f, 1.0f, myBox.ymin(), myBox.ymax()),
176  SYSfit(cz, 0.0f, 1.0f, myBox.zmin(), myBox.zmax()) );
177 
178  // Create a new procedural object
180  // We create the procedural ourselves.
181  // Alternatively, it's also possible to create a procedural by
182  // passing arguments. This would allow the user to control which
183  // procedural gets built.
184  obj->addProcedural( new ray_ChildBox(c, mySize) );
185  }
186 }
virtual void getBoundingBox(UT_BoundingBox &box)
The bounding box is the "object space" bounds of the procedural.
RAY_ProceduralGeo createGeometry() const
Allocate geometry for this procedural.
Procedural primitive for mantra (RAY)
#define SYSabs(a)
Definition: SYS_Math.h:1367
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 T & x(void)
Definition: UT_Vector3.h:581
png_uint_32 i
Definition: png.h:2877
GLsizeiptr size
Definition: glcorearb.h:663
void expandBounds(T relative, T absolute)
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:585
GLfloat f
Definition: glcorearb.h:1925
virtual const char * className() const
virtual int initialize(const UT_BoundingBox *)
Definition: RAY_DemoStamp.C:51
void registerProcedural(RAY_ProceduralFactory *factory)
Modern interface to register procedurals.
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
virtual const char * className() const
Definition: RAY_DemoStamp.C:48
Parameter definition for arguments to RAY_Procedural.
ray_ChildBox(UT_Vector3 &center, fpreal size)
Definition: RAY_DemoStamp.C:42
virtual RAY_ProceduralArg * arguments() const
Provide a const reference to the arguments for the procedural.
Definition: RAY_DemoStamp.C:96
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:612
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:583
double fpreal
Definition: SYS_Types.h:269
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:1607
virtual int initialize(const UT_BoundingBox *)
SYS_FORCE_INLINE void initBounds()
virtual RAY_Procedural * create() const
Create a procedural, and pass ownership of the instance to mantra.
Definition: RAY_DemoStamp.C:95
virtual void getBoundingBox(UT_BoundingBox &box)
The bounding box is the "object space" bounds of the procedural.
Definition: RAY_DemoStamp.C:55
Class to create a procedural.