HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BRAY_PixelFilter.h
Go to the documentation of this file.
1 
2 /*
3  * PROPRIETARY INFORMATION. This software is proprietary to
4  * Side Effects Software Inc., and is not to be reproduced,
5  * transmitted, or disclosed in any way without written permission.
6  *
7  * NAME: BRAY_PixelFilter.h (RAY Library, C++)
8  *
9  * COMMENTS:
10  */
11 
12 #ifndef __BRAY_PixelFilter__
13 #define __BRAY_PixelFilter__
14 
15 #include "BRAY_API.h"
16 #include "BRAY_SampleFilter.h"
17 #include "BRAY_Interface.h"
18 #include "BRAY_Raster.h"
19 #include <UT/UT_UniquePtr.h>
20 #include <UT/UT_IntArray.h>
21 
22 class UT_Options;
23 class UT_BitArray;
24 class BRAY_PixelState;
25 class BRAY_FilterInit;
26 
27 extern "C" {
28  SYS_VISIBILITY_EXPORT extern void newBRAYPixelFilter(void *);
29 }
30 
31 /// Pixel filters take raw samples as generated by the renderer and can adjust
32 /// the sample data values prior to sending it to pixel filtering. A pixel
33 /// filter might average all the samples for a given pixel, or it might just
34 /// select a single sample for the pixel value.
36 {
37 public:
39  {
40  public:
41  virtual ~Factory();
42 
43  /// Create an instance of the BRAY_PixelFilter
44  virtual UT_UniquePtr<BRAY_PixelFilter> instance(const UT_Options *o) const = 0;
45 
46  /// Test if the filter is deprecated
47  virtual bool isDeprecated() const { return false; }
48  };
50 
51  /// @{
52  /// Access to factory
53  static void listFactories(UT_StringArray &result,
54  bool include_deprecated=false);
55 
56  static void registerPlugin(const UT_StringHolder &name, FactoryPtr factory);
57 
58  static UT_UniquePtr<BRAY_PixelFilter> instancePlugin(
59  const UT_StringRef &style,
60  const UT_Options *options=nullptr);
61  static void releasePlugin(UT_UniquePtr<BRAY_PixelFilter> p);
62  static void freePluginCache();
63  /// @}
64 
65  // c-tor
66  BRAY_PixelFilter(const UT_Options *options);
67 
68  // d-tor
69  virtual ~BRAY_PixelFilter();
70 
71  /// Class name for the pixel filter
72  virtual const char *className() const = 0;
73 
74  /// Sample data passed to the pixel filter is the same as the data
75  /// processed by sample filters.
77 
78  /// Process the sample data. Each AOV plane of the @c data will point to a
79  /// contiguous array of sample data which contains at least @c npixels of
80  /// data. The filter should be applied to each pixel in the sample data.
81  ///
82  /// The @c sample_locations are stored as: @code
83  /// v[0] := pixel_x location
84  /// v[1] := pixel_y location
85  /// v[2] := jitter_x location (0 to 1 in pixel)
86  /// v[3] := jitter_y location (0 to 1 in pixel)
87  /// @endcode
88  ///
89  /// Note that with Filtered Importance Sampling, the jitter values may be
90  /// outside the given pixel.
91  ///
92  /// The @c BRAY_PixelState object is an opaque object that should be passed
93  /// to @c writePixel()
94  ///
95  /// The typical filtering code looks like: @code
96  /// for (size_t sample = 0; sample < nsamples; ++sample)
97  /// {
98  /// if (ray_hits.getBit(sample))
99  /// writePixel(pstate, data, sample_locations, i);
100  /// else
101  /// missPixel(pstate, sample_locations, i);
102  /// }
103  /// @endcode
104  virtual void filter(BRAY_PixelState &pstate,
105  const SampleData &data,
106  const UT_Vector4 *sample_locations,
107  const UT_BitArray &ray_hits,
108  size_t nsamples) = 0;
109 
110  /// The checkpoint function is called to save the state of the pixel filter
111  /// to a checkpoint file.
112  virtual bool checkpoint(UT_JSONWriter &w) const = 0;
113 
114  /// @c loadCheckpoint is called to restore the state of the pixel filter.
115  /// In theory, all the settings for the pixel filter should match. Only
116  /// per-pixel data should be different.
117  virtual bool loadCheckpoint(UT_JSONParser &p);
118 
119  /// Write sample data to a pixel. The @c weight is the filter weight for
120  /// the given sample. The sample data is passed directly from the
121  /// BRAY_SampleFilters.
122  void writePixel(BRAY_PixelState &ps,
123  const SampleData &data,
124  const UT_Vector4 *sample_locations,
125  int sidx);
126 
127  /// Overwrite the color in the pixel with the given sample data. This
128  /// doesn't filter data, but writes the data directly to the AOVs,
129  /// overwriting the data that was there previously.
130  void overwritePixel(BRAY_PixelState &ps,
131  const SampleData &data,
132  const UT_Vector4 *sample_locations,
133  int sidx);
134 
135  /// Add to existing data without any filtering.
136  void accumulatePixel(BRAY_PixelState &ps,
137  const SampleData &data,
138  const UT_Vector4 *sample_locations,
139  int sidx);
140 
141  /// If the sample missed, this method can be called to write data more
142  /// efficiently (writing zero to the AOVs).
143  void missPixel(BRAY_PixelState &ps,
144  const SampleData &data,
145  const UT_Vector4 *sample_locations,
146  int sidx);
147 
148  /// Test to see if data has been written to a given sample
149  bool hasWrittenPixel(const BRAY_PixelState &ps,
150  const UT_Vector4 *sample_locations,
151  int sidx) const;
152 
153  /// Return the AOVs that this pixel filter is applied to. This may not be
154  /// a subset of all the AOVs. The filter should only write to these planes
155  /// and no others.
156  const UT_IntArray &aovs() const { return myAOVs; }
157 
158  /// @{
159  /// @private This method is used to create the weight buffer.
160  void initializeWeight(BRAY_FilterInit &init,
161  int xres, int yres,
162  const UT_StringArray &aovnames);
163  void setAOVs(const UT_IntArray &aovs) { myAOVs = aovs; }
164  SYS_HashType optionsHash() const { return myOptionsHash; }
165  /// @}
166 
167  /// By default(0) one pixel filter instance can be applied to any number of
168  /// AOVs. Some filters (e.g. minmax under "min" or "max" mode) shouldn't be
169  /// shared between multiple AOVs, in which case this may return 1.
170  virtual int aovLimit() const { return 0; }
171 
172  /// @{
173  /// Save and restore state
174  bool saveState(UT_JSONWriter &w) const;
175  bool loadState(UT_JSONParser &p);
176  /// @}
177 
178 protected:
179  /// This method can be used to perform any setup required prior to
180  /// filtering. This method may be called when re-rendering. That is, this
181  /// method may be called on an existing object.
182  ///
183  /// The AOV names passed in will be in the same order as the sample data
184  /// passed in.
185  virtual void setResolution(BRAY_FilterInit &init,
186  int xres, int yres,
187  const UT_StringArray &aovnames);
188 
189  /// If the filter needs an additional AOV, you can call this method during
190  /// setResolution(). The function returns the index of the new AOV (or -1
191  /// on failure). If there are errors, the messages will be printed out to
192  /// UT_ErrorLog.
193  ///
194  /// Data from this AOV will be available in the SampleData at the returned
195  /// index.
196  ///
197  /// If options are required, they can be initialized by planeProperties()
198  /// Passing in an empty OptionSet is legal.
199  int addAOV(BRAY_FilterInit &init,
200  const UT_StringHolder &name,
201  const UT_StringHolder &var,
202  int tuple_size,
203  const BRAY::OptionSet &options);
204 
205  /// Create an option set before adding creating an extra AOV
206  BRAY::OptionSet planeProperties(BRAY_FilterInit &init) const;
207 
208 private:
209  UT_IntArray myAOVs;
210  UT_UniquePtr<BRAY_Raster> myWriteCount;
211  SYS_HashType myOptionsHash;
212 };
213 
215 
216 #endif
UT_UniquePtr< Factory > FactoryPtr
GLuint const GLchar * name
Definition: glew.h:1814
#define SYS_VISIBILITY_EXPORT
void setAOVs(const UT_IntArray &aovs)
virtual int aovLimit() const
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:76
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glew.h:2981
Sample data for processing.
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
virtual bool isDeprecated() const
Test if the filter is deprecated.
GLfloat GLfloat p
Definition: glew.h:16321
A map of string to various well defined value types.
Definition: UT_Options.h:84
#define BRAY_API
Definition: BRAY_API.h:12
SYS_VISIBILITY_EXPORT void newBRAYPixelFilter(void *)
GLuint64EXT * result
Definition: glew.h:14007
const UT_IntArray & aovs() const
UT_UniquePtr< BRAY_PixelFilter > BRAY_PixelFilterPtr
SYS_HashType optionsHash() const