HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CHOP_Spring.h
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  * COMMENTS:
27  * Simulates spring-like action on an input channel.
28  */
29 
30 #ifndef __CHOP_Spring__
31 #define __CHOP_Spring__
32 
33 #include <CHOP/CHOP_Realtime.h>
34 
35 // First Page
36 #define ARG_SPR_SPRING_CONSTANT (myParmBase + 0)
37 #define ARG_SPR_MASS (myParmBase + 1)
38 #define ARG_SPR_DAMPING_CONSTANT (myParmBase + 2)
39 #define ARG_SPR_METHOD (myParmBase + 3)
40 #define ARG_SPR_GRAB_INITIAL (myParmBase + 4)
41 #define ARG_SPR_INITIAL_DISPLACEMENT (myParmBase + 5)
42 #define ARG_SPR_INITIAL_VELOCITY (myParmBase + 6)
43 
44 class UT_Interrupt;
45 
46 namespace HDK_Sample {
47 
48 class CHOP_Spring : public CHOP_Realtime
49 {
50 public:
51 
52  static OP_Node *myConstructor(OP_Network *,
53  const char *,
54  OP_Operator *);
59 
60  OP_ERROR cookMyChop(OP_Context &context) override;
62  int start, int end) override;
63 
64  bool updateParmsFlags() override;
65 
66  bool evalVariableValue(
67  fpreal &val, int i, int thread) override;
68  // Add virtual overload that delegates to the super class to avoid
69  // shadow warnings.
71  UT_String &v, int i, int thread) override
72  {
74  v, i, thread);
75  }
76 
77  int usesScope() const override
78  { return 1; };
79  int usesSampleMatch() const override
80  { return 0; };
81  int usesUnits() override
82  { return getInput(0) ? 0 : 1; };
83 
84  int isSteady() const override;
85  const char * getTimeSliceExtension() override
86  { return "spring"; }
87 
88 protected:
89 
90  CHOP_Spring(OP_Network *net,
91  const char *name,
92  OP_Operator *op);
93  ~CHOP_Spring() override;
94 
96  const CL_Track *track,
97  fpreal t) override;
98 
99 private:
100 
101  // First Page
102  int METHOD()
103  { return evalInt(ARG_SPR_METHOD, 0, 0); }
104 
105  fpreal SPRING_CONSTANT(fpreal t)
106  { return evalFloat(ARG_SPR_SPRING_CONSTANT, 0, t); }
107 
108  fpreal MASS(fpreal t)
109  { return evalFloat(ARG_SPR_MASS, 0, t); }
110 
111  void SET_MASS(fpreal t, fpreal f)
112  { setFloat(ARG_SPR_MASS, 0, t, f); }
113 
114  fpreal DAMPING_CONSTANT(fpreal t)
115  { return evalFloat(ARG_SPR_DAMPING_CONSTANT, 0, t); }
116 
117  bool GRAB_INITIAL()
118  { return (bool) evalInt(ARG_SPR_GRAB_INITIAL, 0, 0); }
119 
120  fpreal INITIAL_DISPLACEMENT(fpreal t)
121  { return evalFloat(ARG_SPR_INITIAL_DISPLACEMENT, 0, t); }
122 
123  fpreal INITIAL_VELOCITY(fpreal t)
124  { return evalFloat(ARG_SPR_INITIAL_VELOCITY, 0, t); }
125 
126  int my_NC;
127  int my_C;
128  int myChannelDependent;
129  int mySteady;
130 };
131 
132 } // End HDK_Sample namespace
133 
134 #endif
static OP_VariablePair myVariablePair
Definition: CHOP_Spring.h:56
static CH_LocalVariable myVariableList[]
Definition: CHOP_Spring.h:58
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: CHOP_Spring.C:163
CHOP_Spring(OP_Network *net, const char *name, OP_Operator *op)
Definition: CHOP_Spring.C:171
#define ARG_SPR_DAMPING_CONSTANT
Definition: CHOP_Spring.h:38
OP_ERROR cookMyChop(OP_Context &context) override
Definition: CHOP_Spring.C:186
const GLdouble * v
Definition: glcorearb.h:837
static OP_TemplatePair myTemplatePair
Definition: CHOP_Spring.h:55
GLuint start
Definition: glcorearb.h:475
fpreal evalFloat(int pi, int vi, fpreal t) const
UT_ErrorSeverity
Definition: UT_Error.h:25
#define ARG_SPR_MASS
Definition: CHOP_Spring.h:37
#define ARG_SPR_METHOD
Definition: CHOP_Spring.h:39
#define ARG_SPR_INITIAL_VELOCITY
Definition: CHOP_Spring.h:42
bool updateParmsFlags() override
Definition: CHOP_Spring.C:112
GLfloat f
Definition: glcorearb.h:1926
int usesSampleMatch() const override
Definition: CHOP_Spring.h:79
int usesScope() const override
Definition: CHOP_Spring.h:77
GLuint GLuint end
Definition: glcorearb.h:475
static PRM_Template myTemplateList[]
Definition: CHOP_Spring.h:57
OP_Node * getInput(unsigned idx, bool mark_used=false) const
Returns the node connected to a particular input (may be null).
#define ARG_SPR_INITIAL_DISPLACEMENT
Definition: CHOP_Spring.h:41
GLuint const GLchar * name
Definition: glcorearb.h:786
ut_RealtimeData * newRealtimeDataBlock(const char *name, const CL_Track *track, fpreal t) override
Definition: CHOP_Spring.C:507
bool evalVariableValue(UT_String &v, int i, int thread) override
Definition: CHOP_Spring.h:70
#define ARG_SPR_SPRING_CONSTANT
Definition: CHOP_Spring.h:36
GLdouble t
Definition: glad.h:2397
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
const char * getTimeSliceExtension() override
Definition: CHOP_Spring.h:85
void setFloat(int parmi, int vectori, fpreal t, fpreal value, PRM_AddKeyType add_key=PRM_AK_MARK_PENDING)
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint GLfloat * val
Definition: glcorearb.h:1608
virtual bool evalVariableValue(UT_String &val, int index, int thread)
#define ARG_SPR_GRAB_INITIAL
Definition: CHOP_Spring.h:40
exint evalInt(int pi, int vi, fpreal t) const
OP_ERROR cookMySlice(OP_Context &context, int start, int end) override
Definition: CHOP_Spring.C:401
bool evalVariableValue(fpreal &val, int i, int thread) override
Definition: CHOP_Spring.C:140
int usesUnits() override
Definition: CHOP_Spring.h:81
int isSteady() const override
Definition: CHOP_Spring.C:392