HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CHOP_Stair.h
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 #ifndef __CHOP_Stair__
29 #define __CHOP_Stair__
30 
31 #include <CHOP/CHOP_Node.h>
32 #include <UT/UT_ExpandArray.h>
33 
34 namespace HDK_Sample {
35 
36 #define ARG_STAIR_NUMBER "number"
37 #define ARG_STAIR_HEIGHT "height"
38 #define ARG_STAIR_OFFSET "offset"
39 #define ARG_STAIR_DIRECTION "direction"
40 
41 #define ARG_STAIR_NAME "channelname"
42 #define ARG_STAIR_RANGE CHOP_RangeName.getToken()
43 #define ARG_STAIR_START "start"
44 #define ARG_STAIR_END "end"
45 #define ARG_STAIR_RATE CHOP_SampleRateName.getToken()
46 #define ARG_STAIR_LEFT CHOP_ExtendLeftName.getToken()
47 #define ARG_STAIR_RIGHT CHOP_ExtendRightName.getToken()
48 #define ARG_STAIR_DEFAULT CHOP_DefaultValueName.getToken()
49 
50 class CHOP_Stair : public CHOP_Node
51 {
52 public:
53 
54 
55  static OP_Node *myConstructor(OP_Network*, const char *,
56  OP_Operator *);
61 
62  /// Overridden to generate our channel data
63  OP_ERROR cookMyChop(OP_Context &context);
64 
65  /// Places the handles along the channels
66  void cookMyHandles(OP_Context &context);
67 
68  virtual bool updateParmsFlags();
69 
70  /// Responds to user changes in any handle
71  virtual fpreal handleChanged(CHOP_Handle *handle,
72  CHOP_HandleData *hdata);
73 
74  virtual fpreal shiftStart(fpreal new_offset, fpreal t);
75 
76 protected:
77 
78  CHOP_Stair(OP_Network *net,
79  const char *name, OP_Operator *op);
80  virtual ~CHOP_Stair();
81 
82  /// Returns true because we use the Units parameter.
83  virtual int usesUnits() { return 1; }
84 
85  /// Returns true because we want to use the Scope parameter
86  virtual int usesScope() const { return 0; }
87 
88  /// Stair has some local variables defined, this returns their value.
89  virtual bool evalVariableValue(fpreal &v, int index,
90  int thread);
91  // Add virtual overload that delegates to the super class to avoid
92  // shadow warnings.
93  virtual bool evalVariableValue(UT_String &v, int i,
94  int thread)
95  {
97  v, i, thread);
98  }
99 
100 private:
101 
102  /// @{
103  /// Convenience parameter evaluation functions
104  int NUMBER(fpreal t)
105  { return evalInt(ARG_STAIR_NUMBER, 0, t); }
106 
107  void SET_NUMBER(fpreal t, int v)
108  { setInt(ARG_STAIR_NUMBER, 0, t, v); }
109 
110  fpreal HEIGHT(fpreal t)
111  { return evalFloat(ARG_STAIR_HEIGHT, 0, t); }
112 
113  void SET_HEIGHT(fpreal t, fpreal v)
114  { setFloat(ARG_STAIR_HEIGHT, 0, t, v); }
115 
116  fpreal OFFSET(fpreal t)
117  { return evalFloat(ARG_STAIR_OFFSET, 0, t); }
118 
119  void SET_OFFSET(fpreal t, fpreal v)
120  { setFloat(ARG_STAIR_OFFSET, 0, t, v); }
121 
122  int DIRECTION()
123  { return evalInt(ARG_STAIR_DIRECTION, 0, 0); }
124 
125  void CHAN_NAME(UT_String &label, fpreal t)
126  { evalString(label, ARG_STAIR_NAME, 0, t); }
127 
128  int RANGE(fpreal t)
129  { return evalInt(ARG_STAIR_RANGE, 0, t); }
130 
131  void SET_START(fpreal t, fpreal f)
132  { setFloat(ARG_STAIR_START, 0, t, toUnit(f)); }
133 
134  void SET_END(fpreal t, fpreal f)
135  { setFloat(ARG_STAIR_END, 0, t, toUnit(f, UNITS(), 1)); }
136 
137  fpreal RATE(fpreal t) { return evalFloat(ARG_STAIR_RATE, 0, t); }
138 
139  void SET_RATE(fpreal t, fpreal v)
140  { setFloat(ARG_STAIR_RATE, 0, t, v); }
141 
142  int LEXTEND() { return evalInt(ARG_STAIR_LEFT, 0, 0); }
143  int REXTEND() { return evalInt(ARG_STAIR_RIGHT, 0, 0); }
144  fpreal DEFAULT(fpreal t) { return evalFloat(ARG_STAIR_DEFAULT,0,t); }
145  /// @}
146 
147  void getInterval(fpreal t, fpreal *start, fpreal *end);
148 
149  /// Our local variable for "currently cooking channel"
150  int my_C;
151  /// Our local variable for "number of channels"
152  int my_NC;
153 
154  UT_ExpandArray myExpandArray;
155 };
156 
157 } // End of HDK_Sample namespace
158 
159 #endif
160 
#define ARG_STAIR_DIRECTION
Definition: CHOP_Stair.h:39
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
static CH_LocalVariable myVariableList[]
Definition: CHOP_Stair.h:60
static OP_TemplatePair myTemplatePair
Definition: CHOP_Stair.h:57
static OP_VariablePair myVariablePair
Definition: CHOP_Stair.h:58
virtual fpreal handleChanged(CHOP_Handle *handle, CHOP_HandleData *hdata)
Responds to user changes in any handle.
Definition: CHOP_Stair.C:239
const GLdouble * v
Definition: glcorearb.h:836
GLuint start
Definition: glcorearb.h:474
virtual bool updateParmsFlags()
Definition: CHOP_Stair.C:169
CL_Unit UNITS() const
Definition: CHOP_Node.h:550
#define ARG_STAIR_OFFSET
Definition: CHOP_Stair.h:38
fpreal evalFloat(int pi, int vi, fpreal t) const
UT_ErrorSeverity
Definition: UT_Error.h:25
#define ARG_STAIR_END
Definition: CHOP_Stair.h:44
virtual int usesScope() const
Returns true because we want to use the Scope parameter.
Definition: CHOP_Stair.h:86
virtual bool evalVariableValue(UT_String &v, int i, int thread)
Definition: CHOP_Stair.h:93
#define ARG_STAIR_START
Definition: CHOP_Stair.h:43
#define ARG_STAIR_DEFAULT
Definition: CHOP_Stair.h:48
png_uint_32 i
Definition: png.h:2877
#define ARG_STAIR_NUMBER
Definition: CHOP_Stair.h:36
GLfloat f
Definition: glcorearb.h:1925
#define ARG_STAIR_RIGHT
Definition: CHOP_Stair.h:47
void evalString(UT_String &val, int pi, int vi, fpreal t) const
#define ARG_STAIR_RANGE
Definition: CHOP_Stair.h:42
GLuint GLuint end
Definition: glcorearb.h:474
void setFloat(int parmi, int vectori, fpreal t, fpreal value, int h=0)
#define ARG_STAIR_NAME
Definition: CHOP_Stair.h:41
GLuint const GLchar * name
Definition: glcorearb.h:785
#define ARG_STAIR_RATE
Definition: CHOP_Stair.h:45
virtual fpreal shiftStart(fpreal new_offset, fpreal t)
Definition: CHOP_Stair.C:280
double fpreal
Definition: SYS_Types.h:269
virtual int usesUnits()
Returns true because we use the Units parameter.
Definition: CHOP_Stair.h:83
void setInt(int parmi, int vectori, fpreal t, exint value)
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: CHOP_Stair.C:146
GLuint index
Definition: glcorearb.h:785
virtual bool evalVariableValue(UT_String &val, int index, int thread)
CHOP_Stair(OP_Network *net, const char *name, OP_Operator *op)
Definition: CHOP_Stair.C:153
#define ARG_STAIR_HEIGHT
Definition: CHOP_Stair.h:37
OP_ERROR cookMyChop(OP_Context &context)
Overridden to generate our channel data.
Definition: CHOP_Stair.C:287
exint evalInt(int pi, int vi, fpreal t) const
virtual bool evalVariableValue(fpreal &v, int index, int thread)
Stair has some local variables defined, this returns their value.
Definition: CHOP_Stair.C:129
#define ARG_STAIR_LEFT
Definition: CHOP_Stair.h:46
void cookMyHandles(OP_Context &context)
Places the handles along the channels.
Definition: CHOP_Stair.C:191
static PRM_Template myTemplateList[]
Definition: CHOP_Stair.h:59
fpreal toUnit(fpreal index, CL_Unit unit=UNIT_NONE, int end_width=0) const