HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
COP2_PixelAdd.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  * Addness Op.
27  */
28 #include <UT/UT_DSOVersion.h>
29 #include <UT/UT_WorkBuffer.h>
30 #include <CH/CH_Manager.h>
31 #include <OP/OP_Context.h>
32 #include <OP/OP_OperatorTable.h>
33 
34 #include <PRM/PRM_Include.h>
35 #include <PRM/PRM_Parm.h>
36 
37 #include <RU/RU_PixelFunctions.h>
38 
39 #include "COP2_PixelAdd.h"
40 
41 using namespace HDK_Sample;
42 
43 COP_PIXEL_OP_SWITCHER(1, "Sample Pixel Add");
44 
45 static PRM_Name names[] =
46 {
47  PRM_Name("addend", "Add Value"),
48 };
49 
50 
51 static PRM_Range addRange(PRM_RANGE_UI, -1, PRM_RANGE_UI, 1);
54 {
56 
58  &addRange),
59 
60  PRM_Template(),
61 };
62 
65 
67 
68 const char * COP2_PixelAdd::myInputLabels[] =
69 {
70  "Image to Add to",
71  "Mask Input",
72  0
73 };
74 
75 OP_Node *
77  const char *name,
78  OP_Operator *op)
79 {
80  return new COP2_PixelAdd(net, name, op);
81 }
82 
83 COP2_PixelAdd::COP2_PixelAdd(OP_Network *parent,
84  const char *name,
85  OP_Operator *entry)
86  : COP2_PixelOp(parent, name, entry)
87 {
88 }
89 
90 COP2_PixelAdd::~COP2_PixelAdd() { }
91 
92 
93 
94 // this is the pixel function, which does the work.
95 namespace HDK_Sample {
97 {
98 public:
99  cop2_AddFunc(float r,float g, float b, float a)
100  { myAddend[0] = r; myAddend[1] = g; myAddend[2] = b; myAddend[3] = a; }
101 protected:
102 
103  // the operation differs per component.
104  virtual bool eachComponentDifferent() const { return true; }
105 
106  // we don't need to process all the compoents together, as a vector.
107  virtual bool needAllComponents() const { return false; }
108 
109 
110  // Here's the heart of the pixel function - it simply adds our addend to
111  // the passed in val for the given component. This is the scalar version.
112  static float add(RU_PixelFunction *pf, float val, int comp)
113  { return val +((cop2_AddFunc*)pf)->myAddend[comp]; }
114 
115  // we return the static function above as our scalar function.
116  virtual RUPixelFunc getPixelFunction() const { return add; }
117 
118  // --or--
119 
120  // These are the methods you would use for a vector function. They are
121  // not used in this case, since needAllComponents is false.
122  // You can define a function with both a scalar and a vector function,
123  // and switch between the two based on parameters.
124 
125  static void addvec(RU_PixelFunction *f, float **vals,
126  const bool *scope)
127  {
128  cop2_AddFunc *pf = (cop2_AddFunc *) f;
129 
130  if(vals[0] && scope[0]) *vals[0] = *vals[0] + pf->myAddend[0];
131  if(vals[1] && scope[1]) *vals[1] = *vals[1] + pf->myAddend[1];
132  if(vals[2] && scope[2]) *vals[2] = *vals[2] + pf->myAddend[2];
133  if(vals[3] && scope[3]) *vals[3] = *vals[3] + pf->myAddend[3];
134  }
135 
136  // we return the static function above as our vector function.
137  virtual RUVectorFunc getVectorFunction() const { return addvec; }
138 
139 private:
140  float myAddend[4];
141 };
142 }
143 
144 
145 
146 // This is where we create and return our a new pixel function, defined above.
147 // Parms can be evaluated in this method.
148 
150 COP2_PixelAdd::addPixelFunction(const TIL_Plane*plane,int,float t, int,int,int)
151 {
152  // The frame scope effect is only used if parms on the frame scope page
153  // are altered.
154  int index = mySequence.getImageIndex(t);
155  float effect = getFrameScopeEffect(index);
156  float r,g,b,a;
157 
158  // Note that we treat the alpha plane differently than other planes.
159  if(plane->isAlphaPlane())
160  {
161  // use the alpha value for the alpha plane.
162  r = g = b = a = ADD(3, t) * effect;
163  }
164  else
165  {
166  // all other planes, use comps 0-3.
167  r = ADD(0,t) * effect;
168  g = ADD(1,t) * effect;
169  b = ADD(2,t) * effect;
170  a = ADD(3,t) * effect;
171  }
172 
173  return new cop2_AddFunc(r,g,b,a);
174 }
175 
176 const char *
177 COP2_PixelAdd::getOperationInfo()
178 {
179  // return a small string describing what this function does in the info
180  // popup.
181  fpreal t = CHgetEvalTime();
182  int index = mySequence.getImageIndex(t);
183  float effect = getFrameScopeEffect(index);
184 
185  static UT_WorkBuffer info;
186 
187  info.sprintf("Add (%g, %g, %g, %g)",
188  ADD(0,t)*effect, ADD(1,t)*effect,
189  ADD(2,t)*effect, ADD(3,t)*effect);
190 
191  return info.buffer();
192 }
193 
194 void
196 {
197  table->addOperator(new OP_Operator("hdk_samplepixadd",
198  "HDK Sample Pixel Add",
201  1,
202  2, // optional mask input
204 }
205 
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: COP2_PixelAdd.C:76
void newCop2Operator(OP_OperatorTable *table)
COP_PIXEL_OP_SWITCHER(1,"Sample Pixel Add")
TIL_Sequence mySequence
Definition: COP2_Node.h:1295
static PRM_Template myTemplateList[]
Definition: COP2_PixelAdd.h:51
virtual RUVectorFunc getVectorFunction() const
virtual float getFrameScopeEffect(int image_index)
static void addvec(RU_PixelFunction *f, float **vals, const bool *scope)
GLboolean GLboolean g
Definition: glcorearb.h:1221
virtual RUPixelFunc getPixelFunction() const
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
cop2_AddFunc(float r, float g, float b, float a)
Definition: COP2_PixelAdd.C:99
bool addOperator(OP_Operator *op, std::ostream *err=nullptr)
static OP_VariablePair myVariablePair
Definition: COP2_Node.h:619
PRM_API const PRM_Type PRM_RGB_J
GLfloat f
Definition: glcorearb.h:1925
virtual bool eachComponentDifferent() const
static const char * myInputLabels[]
Definition: COP2_PixelAdd.h:53
static float add(RU_PixelFunction *pf, float val, int comp)
fpreal CHgetEvalTime()
Definition: CH_Manager.h:1605
GLuint const GLchar * name
Definition: glcorearb.h:785
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
PRM_API const PRM_Type PRM_SWITCHER
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
static OP_TemplatePair myTemplatePair
Definition: COP2_PixelOp.h:35
#define TOOL_PARM
Definition: COP2_Common.h:26
PRM_API PRM_Default PRMoneDefaults[]
PRM_API PRM_Name PRMswitcherName
double fpreal
Definition: SYS_Types.h:263
static OP_TemplatePair myTemplatePair
Definition: COP2_PixelAdd.h:49
virtual bool needAllComponents() const
virtual RU_PixelFunction * addPixelFunction(const TIL_Plane *, int, float t, int, int, int thread)
GLuint index
Definition: glcorearb.h:785
GLuint GLfloat * val
Definition: glcorearb.h:1607
const char * buffer() const
static OP_VariablePair myVariablePair
Definition: COP2_PixelAdd.h:50
GLboolean r
Definition: glcorearb.h:1221
void(* RUVectorFunc)(RU_PixelFunction *, float **, const bool *)
exint getImageIndex(double t, int clamp_range=1, int round_off=SEQUENCE_NEAREST) const
float(* RUPixelFunc)(RU_PixelFunction *, float, int)
bool isAlphaPlane() const