00001 /* 00002 * Copyright (c) 2012 00003 * Side Effects Software Inc. All rights reserved. 00004 * 00005 * Redistribution and use of Houdini Development Kit samples in source and 00006 * binary forms, with or without modification, are permitted provided that the 00007 * following conditions are met: 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. The name of Side Effects Software may not be used to endorse or 00011 * promote products derived from this software without specific prior 00012 * written permission. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS 00015 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00017 * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00019 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00020 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00021 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00022 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00023 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 * 00025 *---------------------------------------------------------------------------- 00026 * This operator does a simple pixel modification on its input. 00027 */ 00028 #ifndef _COP2_SAMPLEFILTER_H_ 00029 #define _COP2_SAMPLEFILTER_H_ 00030 00031 #include <COP2/COP2_Context.h> 00032 #include <COP2/COP2_MaskOp.h> 00033 00034 namespace HDK_Sample { 00035 00036 /// @brief Simple example of a kernel filter. 00037 00038 /// This is an HDK example of a 3x3 kernel filter which uses template classes 00039 /// to abstract the operation for various data formats. It also demonstrates 00040 /// how to deal with fetching input areas larger than a tile, and how to 00041 /// enlarging the canvas for the COP. 00042 class COP2_SampleFilter : public COP2_MaskOp 00043 { 00044 public: 00045 /// All nodes are instantiated via a myConstructor method. 00046 static OP_Node *myConstructor(OP_Network*, const char *, 00047 OP_Operator *); 00048 00049 /// @{ 00050 /// Parameters, local variables and input labals. 00051 static OP_TemplatePair myTemplatePair; 00052 static OP_VariablePair myVariablePair; 00053 static PRM_Template myTemplateList[]; 00054 static CH_LocalVariable myVariableList[]; 00055 static const char *myInputLabels[]; 00056 /// @} 00057 00058 /// Given an area of the image to cook, indicate which parts of the input's 00059 /// image are required 00060 virtual void getInputDependenciesForOutputArea( 00061 COP2_CookAreaInfo &output_area, 00062 const COP2_CookAreaList &input_areas, 00063 COP2_CookAreaList &needed_areas); 00064 protected: 00065 /// This operation expands the canvas bounds by 1 pixel in all directions. 00066 /// computeImageBounds() announces this to the COP engine. 00067 virtual void computeImageBounds(COP2_Context &context); 00068 00069 /// Returns a new context instance with the parameters for the filter in 00070 /// it, to be used by the many threads on the tiles. 00071 virtual COP2_ContextData *newContextData(const TIL_Plane *p, 00072 int array_index, 00073 float t, 00074 int xres, int yres, 00075 int thread, 00076 int max_threads); 00077 00078 /// COP2_MaskOp defines lots of nice mask blending operations in 00079 /// cookMyTile(), and defines doCookMyTile for us to override instead. 00080 /// This is where the actual image operation is performed. 00081 virtual OP_ERROR doCookMyTile(COP2_Context &context, 00082 TIL_TileList *tilelist); 00083 00084 /// Returns a description of the operation for the node info popup. 00085 virtual const char *getOperationInfo(); 00086 00087 virtual ~COP2_SampleFilter(); 00088 private: 00089 COP2_SampleFilter(OP_Network *parent, const char *name, 00090 OP_Operator *entry); 00091 00092 /// @{ 00093 /// Parameter evaluation method; can call evalFloat directly as well. 00094 float LEFT(float t) 00095 { return evalFloat("left",0,t); } 00096 00097 float RIGHT(float t) 00098 { return evalFloat("right",0,t); } 00099 00100 float TOP(float t) 00101 { return evalFloat("top",0,t); } 00102 00103 float BOTTOM(float t) 00104 { return evalFloat("bottom",0,t); } 00105 /// @} 00106 }; 00107 00108 /// Storage class for our parameters and the kernel 00109 class cop2_SampleFilterContext : public COP2_ContextData 00110 { 00111 public: 00112 cop2_SampleFilterContext() 00113 : myLeft(0.0f), myRight(0.0f), myTop(0.0f), myBottom(0.0f), 00114 myKernel(NULL) 00115 {} 00116 00117 virtual ~cop2_SampleFilterContext() { delete [] myKernel; } 00118 00119 /// When true, this context data object is recreated for each plane. 00120 virtual bool createPerPlane() const { return false; } 00121 00122 /// When true, this context data object is recreated for each resolution 00123 /// cooked. 00124 virtual bool createPerRes() const { return true; } 00125 00126 /// When true, this context data object is recreated for each frame. In most 00127 /// cases, this returns true since parameters can be animated. 00128 virtual bool createPerTime() const { return true; } 00129 00130 /// When true, each thread gets its own version of a context data. This is 00131 /// useful if the context data contains allocated memory to be used for 00132 /// intermediate steps. 00133 virtual bool createPerThread() const{ return false; } 00134 00135 /// @{ 00136 /// Cached Parameters 00137 float myLeft; 00138 float myRight; 00139 float myTop; 00140 float myBottom; 00141 /// @} 00142 00143 /// Kernel filter derived from parameters 00144 float *myKernel; 00145 }; 00146 00147 } // End HDK_Sample namespace 00148 00149 #endif
1.5.9