HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
COP2_SampleFilter.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  * This operator does a simple pixel modification on its input.
27  */
28 #ifndef _COP2_SAMPLEFILTER_H_
29 #define _COP2_SAMPLEFILTER_H_
30 
31 #include <COP2/COP2_Context.h>
32 #include <COP2/COP2_MaskOp.h>
33 
34 namespace HDK_Sample {
35 
36 /// @brief Simple example of a kernel filter.
37 
38 /// This is an HDK example of a 3x3 kernel filter which uses template classes
39 /// to abstract the operation for various data formats. It also demonstrates
40 /// how to deal with fetching input areas larger than a tile, and how to
41 /// enlarging the canvas for the COP.
43 {
44 public:
45  /// All nodes are instantiated via a myConstructor method.
46  static OP_Node *myConstructor(OP_Network*, const char *,
47  OP_Operator *);
48 
49  /// @{
50  /// Parameters, local variables and input labals.
55  static const char *myInputLabels[];
56  /// @}
57 
58  /// Given an area of the image to cook, indicate which parts of the input's
59  /// image are required
61  COP2_CookAreaInfo &output_area,
62  const COP2_CookAreaList &input_areas,
63  COP2_CookAreaList &needed_areas);
64 protected:
65  /// This operation expands the canvas bounds by 1 pixel in all directions.
66  /// computeImageBounds() announces this to the COP engine.
67  virtual void computeImageBounds(COP2_Context &context);
68 
69  /// Returns a new context instance with the parameters for the filter in
70  /// it, to be used by the many threads on the tiles.
71  virtual COP2_ContextData *newContextData(const TIL_Plane *p,
72  int array_index,
73  float t,
74  int xres, int yres,
75  int thread,
76  int max_threads);
77 
78  /// COP2_MaskOp defines lots of nice mask blending operations in
79  /// cookMyTile(), and defines doCookMyTile for us to override instead.
80  /// This is where the actual image operation is performed.
81  virtual OP_ERROR doCookMyTile(COP2_Context &context,
82  TIL_TileList *tilelist);
83 
84  /// Returns a description of the operation for the node info popup.
85  virtual const char *getOperationInfo();
86 
87  virtual ~COP2_SampleFilter();
88 private:
89  COP2_SampleFilter(OP_Network *parent, const char *name,
90  OP_Operator *entry);
91 
92  /// @{
93  /// Parameter evaluation method; can call evalFloat directly as well.
94  fpreal LEFT(fpreal t)
95  { return evalFloat("left",0,t); }
96 
97  fpreal RIGHT(fpreal t)
98  { return evalFloat("right",0,t); }
99 
100  fpreal TOP(fpreal t)
101  { return evalFloat("top",0,t); }
102 
103  fpreal BOTTOM(fpreal t)
104  { return evalFloat("bottom",0,t); }
105  /// @}
106 };
107 
108 /// Storage class for our parameters and the kernel
110 {
111 public:
113  : myLeft(0.0f), myRight(0.0f), myTop(0.0f), myBottom(0.0f),
114  myKernel(NULL)
115  {}
116 
117  virtual ~cop2_SampleFilterContext() { delete [] myKernel; }
118 
119  /// When true, this context data object is recreated for each plane.
120  virtual bool createPerPlane() const { return false; }
121 
122  /// When true, this context data object is recreated for each resolution
123  /// cooked.
124  virtual bool createPerRes() const { return true; }
125 
126  /// When true, this context data object is recreated for each frame. In most
127  /// cases, this returns true since parameters can be animated.
128  virtual bool createPerTime() const { return true; }
129 
130  /// When true, each thread gets its own version of a context data. This is
131  /// useful if the context data contains allocated memory to be used for
132  /// intermediate steps.
133  virtual bool createPerThread() const{ return false; }
134 
135  /// @{
136  /// Cached Parameters
137  float myLeft;
138  float myRight;
139  float myTop;
140  float myBottom;
141  /// @}
142 
143  /// Kernel filter derived from parameters
144  float *myKernel;
145 };
146 
147 } // End HDK_Sample namespace
148 
149 #endif
Simple example of a kernel filter.
Storage class for our parameters and the kernel.
float * myKernel
Kernel filter derived from parameters.
virtual bool createPerPlane() const
When true, this context data object is recreated for each plane.
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
All nodes are instantiated via a myConstructor method.
virtual void getInputDependenciesForOutputArea(COP2_CookAreaInfo &output_area, const COP2_CookAreaList &input_areas, COP2_CookAreaList &needed_areas)
fpreal evalFloat(int pi, int vi, fpreal t) const
UT_ErrorSeverity
Definition: UT_Error.h:25
GLfloat f
Definition: glcorearb.h:1925
virtual COP2_ContextData * newContextData(const TIL_Plane *p, int array_index, float t, int xres, int yres, int thread, int max_threads)
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual OP_ERROR doCookMyTile(COP2_Context &context, TIL_TileList *tilelist)
double fpreal
Definition: SYS_Types.h:263
static const char * myInputLabels[]
static OP_TemplatePair myTemplatePair
static OP_VariablePair myVariablePair
virtual const char * getOperationInfo()
Returns a description of the operation for the node info popup.
static PRM_Template myTemplateList[]
virtual void computeImageBounds(COP2_Context &context)
static CH_LocalVariable myVariableList[]