HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_RasterFilter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: TIL_MiscHelper.h (TIL Library, C++)
7  *
8  * COMMENTS: A generic interface to provide filters for rasters with
9  * multiple raster planes. Examples of this might include
10  * denoisers which read from multiple input planes and write to
11  * multiple output planes.
12  *
13  */
14 
15 #ifndef TIL_MiscHelper_H
16 #define TIL_MiscHelper_H
17 
18 #include "TIL_API.h"
19 #include "TIL_Defines.h"
20 
21 #include <UT/UT_NonCopyable.h>
22 #include <UT/UT_Options.h>
23 #include <UT/UT_StringArray.h>
24 #include <UT/UT_StringHolder.h>
25 #include <UT/UT_StringMap.h>
26 #include <UT/UT_UniquePtr.h>
27 #include <SYS/SYS_Visibility.h>
28 
29 class PXL_Raster;
30 class UT_Options;
31 
32 /// Apply arbitrary filters to PXL_Raster image(s).
33 ///
34 /// The DSO must implement "newRasterFilter" function which should create new
35 /// filters by calling TIL_RasterFilter::registerFactory(). Image filters will
36 /// be searched for in $HOUDINI_DSO_PATH/img_filter.
37 ///
38 /// When the filter is instantiated, the caller will initialize the filter
39 /// calling @c setOptions. This is only called one time, though the filter may
40 /// be invoked multiple times.
41 ///
42 /// Prior to invoking the filter, the @c reset() method will be called. This
43 /// lets the filter reset any information that changes from run to run.
44 ///
45 /// The caller will then set up any optional read-only auxilliary rasters the
46 /// filter may need for processing. That is, the caller will call @c
47 /// setAuxPlane zero or more times.
48 ///
49 /// After the filter is reset and auxilliary planes are added, the @c apply()
50 /// method will finally be called. This should modify the raster passed in to
51 /// create the resulting image. It's possible the apply() method may be called
52 /// multiple times before reset() is called again.
54 {
55 public:
57 
58  /// The factory to define a filter
60  {
61  Factory() = default;
62  virtual ~Factory();
64  virtual const UT_StringHolder &name() const = 0;
65  virtual const UT_StringHolder &label() const = 0;
66  virtual TIL_RasterFilterPtr newFilter() const = 0;
67  };
68 
69  /// @{
70  /// Constructor/Destructor
72  virtual ~TIL_RasterFilter() {};
73  /// @}
74 
76 
77  /// @{
78  /// Get tokens that are used to store auxilliary planes
79  static const UT_StringHolder &albedoToken();
80  static const UT_StringHolder &normalToken();
81  static const UT_StringHolder &mvectorToken();
82  static const UT_StringHolder &prevfrToken();
83  /// @}
84 
85  /// Register a new factory. Set HOUDINI_DSO_ERROR=1 to get information on
86  /// why the filter might not be installed.
87  static void registerFactory(UT_UniquePtr<Factory> factory);
88 
89  /// Remove a factory from the list
90  static void removeFactory(const UT_StringRef &name);
91 
92  /// Get a list of all the filters
93  static void getFilters(UT_Array<const Factory *> &filters);
94 
95  // Allocate a filter of a given name
96  static TIL_RasterFilterPtr allocFilter(const UT_StringRef &name);
97 
98  /// For debugging
99  virtual const char *className() const = 0;
100 
101  /// Initiaze the filter with user specified options. This method is only
102  /// called once. If the filter isn't valid, the @c myErrorString member
103  /// should be set to a meaningful error and the function should return
104  /// false.
105  ///
106  /// Aside from setting any specific options, this is also the time you
107  /// should build myAuxPlaneNames. This lets the caller know which extra
108  /// AOVs you can read from. Not all of them may exist, but this lets the
109  /// caller know which planes you can look at.
110  virtual bool setOptions(const UT_Options &options) { return true; }
111 
112  /// Set up an auxilliary plane. This is a raster which isn't actually
113  /// modified, but is used in the filtering (for example a mask). The
114  /// caller looks at the @c myAuxPlaneNames list to see which rasters you
115  /// might require. If they are available, they will be stashed in this
116  /// array.
117  void setAuxPlane(const UT_StringHolder &planename,
118  const PXL_Raster *raster)
119  {
120  myAuxPlanes[planename] = raster;
121  }
122 
123  /// Returns false if fail
124  virtual bool apply(PXL_Raster *raster) = 0;
125 
126  /// Reset and get ready for a new filter. If you subclass this method,
127  /// please make sure to call the base class method.
128  virtual void reset()
129  {
130  myAuxPlanes.clear();
131  }
132 
133  /// Get the list of aux plane names
135  { return myAuxPlaneNames; }
136 
137  /// Get stored error msg in case apply() fails. Sub-classes can set @c
138  /// myErrorString to something meaningful for the caller.
140  { return myErrorString; }
141 
142  /// If the filter can run in a few milliseconds, you can try returning
143  /// true.
144  virtual bool isInteractive() const { return false; }
145 
146 protected:
150 };
151 
153 
154 extern "C" {
155  /// DSO function called. This function can register one or more filters.
156  /// Only filters which are supported should be registered.
158 }
159 
160 #endif
UT_StringHolder myErrorString
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
SYS_VISIBILITY_EXPORT void newRasterFilter()
UT_StringArray myAuxPlaneNames
#define SYS_VISIBILITY_EXPORT
void setAuxPlane(const UT_StringHolder &planename, const PXL_Raster *raster)
const UT_StringHolder & getErrorString() const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
const UT_StringArray & getAuxPlaneNames() const
Get the list of aux plane names.
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
virtual bool isInteractive() const
HUSD_API const char * raster()
virtual void reset()
GLuint const GLchar * name
Definition: glcorearb.h:786
TIL_RasterFilter::TIL_RasterFilterPtr TIL_RasterFilterPtr
A map of string to various well defined value types.
Definition: UT_Options.h:84
The factory to define a filter.
#define TIL_API
Definition: TIL_API.h:10
UT_StringMap< const PXL_Raster * > myAuxPlanes
UT_UniquePtr< TIL_RasterFilter > TIL_RasterFilterPtr
virtual ~TIL_RasterFilter()