HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
COP2_SampleFilter.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  * 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) override;
64 protected:
65  /// This operation expands the canvas bounds by 1 pixel in all directions.
66  /// computeImageBounds() announces this to the COP engine.
67  void computeImageBounds(COP2_Context &context) override;
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.
72  int array_index,
73  float t,
74  int xres, int yres,
75  int thread,
76  int max_threads) override;
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.
82  TIL_TileList *tilelist) override;
83 
84  /// Returns a description of the operation for the node info popup.
85  const char *getOperationInfo() override;
86 
87  ~COP2_SampleFilter() override;
88 
89 private:
90  COP2_SampleFilter(OP_Network *parent, const char *name,
91  OP_Operator *entry);
92 
93  /// @{
94  /// Parameter evaluation method; can call evalFloat directly as well.
95  fpreal LEFT(fpreal t)
96  { return evalFloat("left",0,t); }
97 
98  fpreal RIGHT(fpreal t)
99  { return evalFloat("right",0,t); }
100 
101  fpreal TOP(fpreal t)
102  { return evalFloat("top",0,t); }
103 
104  fpreal BOTTOM(fpreal t)
105  { return evalFloat("bottom",0,t); }
106  /// @}
107 };
108 
109 /// Storage class for our parameters and the kernel
111 {
112 public:
114  : myLeft(0.0f), myRight(0.0f), myTop(0.0f), myBottom(0.0f),
115  myKernel(NULL)
116  {}
117 
118  ~cop2_SampleFilterContext() override { delete [] myKernel; }
119 
120  /// When true, this context data object is recreated for each plane.
121  bool createPerPlane() const override { return false; }
122 
123  /// When true, this context data object is recreated for each resolution
124  /// cooked.
125  bool createPerRes() const override { return true; }
126 
127  /// When true, this context data object is recreated for each frame. In most
128  /// cases, this returns true since parameters can be animated.
129  bool createPerTime() const override { return true; }
130 
131  /// When true, each thread gets its own version of a context data. This is
132  /// useful if the context data contains allocated memory to be used for
133  /// intermediate steps.
134  bool createPerThread() const override{ return false; }
135 
136  /// @{
137  /// Cached Parameters
138  float myLeft;
139  float myRight;
140  float myTop;
141  float myBottom;
142  /// @}
143 
144  /// Kernel filter derived from parameters
145  float *myKernel;
146 };
147 
148 } // End HDK_Sample namespace
149 
150 #endif
Simple example of a kernel filter.
Storage class for our parameters and the kernel.
float * myKernel
Kernel filter derived from parameters.
bool createPerPlane() const override
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.
OP_ERROR doCookMyTile(COP2_Context &context, TIL_TileList *tilelist) override
void computeImageBounds(COP2_Context &context) override
fpreal evalFloat(int pi, int vi, fpreal t) const
UT_ErrorSeverity
Definition: UT_Error.h:25
GLfloat f
Definition: glcorearb.h:1926
GLuint const GLchar * name
Definition: glcorearb.h:786
void getInputDependenciesForOutputArea(COP2_CookAreaInfo &output_area, const COP2_CookAreaList &input_areas, COP2_CookAreaList &needed_areas) override
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
static const char * myInputLabels[]
fpreal64 fpreal
Definition: SYS_Types.h:277
static OP_TemplatePair myTemplatePair
static OP_VariablePair myVariablePair
COP2_ContextData * newContextData(const TIL_Plane *p, int array_index, float t, int xres, int yres, int thread, int max_threads) override
static PRM_Template myTemplateList[]
const char * getOperationInfo() override
Returns a description of the operation for the node info popup.
static CH_LocalVariable myVariableList[]