HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_PixelFilter.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_PixelFilter.h (TIL Library, C++)
7 *
8 * COMMENTS: Pixel filter classes, for processing TIL_AdaptiveImage samples.
9 */
10 
11 #pragma once
12 
13 #ifndef __TIL_PixelFilter__
14 #define __TIL_PixelFilter__
15 
16 #include "TIL_API.h"
17 #include "TIL_Raster.h"
18 #include <PXL/PXL_Common.h>
19 #include <UT/UT_Assert.h>
20 #include <UT/UT_NonCopyable.h>
21 #include <SYS/SYS_Inline.h>
22 
23 class TIL_AdaptiveImage;
24 
25 /// This is the super-duper-class for all pixel filters in TIL.
27 {
28 public:
29  virtual ~TIL_PixelFilter() {}
31 
32  virtual void filterPlaneVirtual(
34  TIL_Raster &dest,
35  int planei,
36  int plane_src_components) const = 0;
37 
38  /// When vetsSamples() returns true, this should be called
39  /// so that the pixel filter can decide how to combine samples,
40  /// instead of just summing.
41  /// NOTE: nnew_samples is 1 when adding a new sample,
42  /// but may be more than 1 when combining pixels
43  /// into higher levels of the TIL_AdaptiveImage.
44  virtual void combineSample(
45  int ncomponents,
46  exint nexisting_samples,
47  float *existing,
48  exint nnew_samples,
49  const float *new_sample) const
50  {
51  UT_ASSERT_MSG(0, "Either this should be overridden by the subclass, or it shouldn't be called. Check vetsSamples().");
52  // This is just an example of the default behaviour.
53  for (int i = 0; i < ncomponents; ++i)
54  existing[i] += new_sample[i];
55  }
56 
57  /// Returns true iff this filter requires TIL_AdaptiveImage
58  /// to initialize TIL_AdaptiveImage::Level::mySumsOfSquares for
59  /// the plane that this filter is applied to.
61  bool needsSquares() const
62  {
63  return myNeedsSquares;
64  }
65 
66  /// Returns true iff this filter requires TIL_AdaptiveImage
67  /// to initialize TIL_AdaptiveImage::Level::myWeights from
68  /// the adaptivity plane.
70  bool needsWeights() const
71  {
72  return myNeedsWeights;
73  }
74 
75  /// Returns true iff TIL_AdaptiveImage needs to call
76  /// combineSample when inserting a sample to a plane
77  /// with this filter.
79  bool vetsSamples() const
80  {
81  return myVetsSamples;
82  }
83 
84  /// Returns false iff TIL_AdaptiveImage needs to create/delete it.
85  /// true means that it's owned globally, so will be deleted when the
86  /// process exits.
87  virtual bool ownedBySingleton() const
88  {
89  return false;
90  }
91 
92 protected:
94  : myNeedsSquares(false)
95  , myVetsSamples(false)
96  , myNeedsWeights(false)
97  {}
99  bool needs_squares,
100  bool vets_samples,
101  bool needs_weights)
102  : myNeedsSquares(needs_squares)
103  , myVetsSamples(vets_samples)
104  , myNeedsWeights(needs_weights)
105  {}
106 
107 private:
108  const bool myNeedsSquares:1;
109  const bool myNeedsWeights:1;
110  const bool myVetsSamples:1;
111 };
112 
113 /// Pixel filters should inherit from this using the "curiously-recurring
114 /// template pattern", so that this class can call the templated filterPlane
115 /// function in the subclass, e.g.:
116 /// class TIL_MyPixelFilter : public TIL_PixelFilterT<TIL_MyPixelFilter>
117 /// {
118 /// template<int NSRCCOMPONENTS,typename T,int NDSTCOMPONENTS,bool INTERLEAVED>
119 /// void filterPlane(
120 /// const TIL_AdaptiveImage &src,
121 /// PXL_RasterWrapper<T,NDSTCOMPONENTS,INTERLEAVED> dest,
122 /// int planei,
123 /// int plane_start_src_component) const;
124 /// };
125 /// The primary advantage of this middle class is to unpack how the raster
126 /// is stored, so that it can be accessed more efficiently in the pixel filter.
127 /// Of course, this means that filterPlane will get compiled 45 times, for the 5
128 /// data types and 9 packing formats, (including the two 2-to-3 formats).
129 template<typename SUBCLASS>
131 {
132 public:
133  typedef SUBCLASS SubclassType;
134 
135  ~TIL_PixelFilterT() override {}
136 
137  void filterPlaneVirtual(
138  const TIL_AdaptiveImage &src,
139  TIL_Raster &dest,
140  int planei,
141  int plane_src_components) const override;
142 
143 protected:
145  bool needs_squares=false,
146  bool vets_samples=false,
147  bool needs_weights=false)
148  : TIL_PixelFilter(needs_squares, vets_samples, needs_weights)
149  {}
150 
151 private:
152  template<int NSRCCOMPONENTS,int NDSTCOMPONENTS,bool INTERLEAVED>
153  void filterPlanePart(
154  const TIL_AdaptiveImage &src,
155  TIL_Raster &dest,
156  int planei) const;
157 };
158 
159 class TIL_API TIL_PixelFilterPixelLevel : public TIL_PixelFilterT<TIL_PixelFilterPixelLevel>
160 {
161 public:
162  template<int NSRCCOMPONENTS,typename T,int NDSTCOMPONENTS,bool INTERLEAVED>
163  void filterPlane(
164  const TIL_AdaptiveImage &src,
166  int planei) const;
167 
168  bool ownedBySingleton() const override
169  {
170  return true;
171  }
172 
174 };
175 
176 class TIL_API TIL_PixelFilterSampleCount : public TIL_PixelFilterT<TIL_PixelFilterSampleCount>
177 {
178 public:
179  template<int NSRCCOMPONENTS,typename T,int NDSTCOMPONENTS,bool INTERLEAVED>
180  void filterPlane(
181  const TIL_AdaptiveImage &src,
183  int planei) const;
184 
185  bool ownedBySingleton() const override
186  {
187  return true;
188  }
189 
191 };
192 
193 class TIL_API TIL_PixelFilterPower2Block : public TIL_PixelFilterT<TIL_PixelFilterPower2Block>
194 {
195 public:
196  template<int NSRCCOMPONENTS,typename T,int NDSTCOMPONENTS,bool INTERLEAVED>
197  void filterPlane(
198  const TIL_AdaptiveImage &src,
200  int planei) const;
201 
202  bool ownedBySingleton() const override
203  {
204  return true;
205  }
206 
208 };
209 
210 template<bool IS_MAX>
211 class TIL_API TIL_PixelFilterMinMax : public TIL_PixelFilterT<TIL_PixelFilterMinMax<IS_MAX> >
212 {
214 public:
216  : Base(false,true) // vets_samples
217  {}
218 
219  template<int NSRCCOMPONENTS,typename T,int NDSTCOMPONENTS,bool INTERLEAVED>
220  void filterPlane(
221  const TIL_AdaptiveImage &src,
223  int planei) const;
224 
226  int ncomponents,
227  exint nexisting_samples,
228  float *existing,
229  exint nnew_samples,
230  const float *new_sample) const override
231  {
232  if (nnew_samples == 0)
233  return;
234 
235  if (nexisting_samples == 0)
236  {
237  for (int i = 0; i < ncomponents; ++i)
238  existing[i] = new_sample[i];
239  return;
240  }
241 
242  if (IS_MAX)
243  {
244  for (int i = 0; i < ncomponents; ++i)
245  {
246  float v = new_sample[i];
247  if (v > existing[i])
248  existing[i] = v;
249  }
250  }
251  else
252  {
253  // min
254  for (int i = 0; i < ncomponents; ++i)
255  {
256  float v = new_sample[i];
257  if (v < existing[i])
258  existing[i] = v;
259  }
260  }
261  }
262 
263  bool ownedBySingleton() const override
264  {
265  return true;
266  }
267 
269 };
270 
271 template<bool LEVEL_INTERP>
272 class TIL_API TIL_PixelFilterDebug : public TIL_PixelFilterT<TIL_PixelFilterDebug<LEVEL_INTERP> >
273 {
275 public:
276  /// NOTE: This does not need its own plane's squares, just the adaptivity plane's weights.
278  : Base(false,false,true) // needs_squares,vets_samples,needs_weights
279  , myLevel(level)
280  {}
281 
282  template<int NSRCCOMPONENTS,typename T,int NDSTCOMPONENTS,bool INTERLEAVED>
283  void filterPlane(
284  const TIL_AdaptiveImage &src,
286  int planei) const;
287 
288 private:
289  int myLevel;
290 };
291 
292 #if 1
293 class TIL_API TIL_PixelFilterBlurThreshold : public TIL_PixelFilterT<TIL_PixelFilterBlurThreshold>
294 {
296 public:
298  : Base(true) // needs_squares
299  , myThresholdSquared(threshold*threshold)
300  {}
301 
302  template<int NSRCCOMPONENTS,typename T,int NDSTCOMPONENTS,bool INTERLEAVED>
303  void filterPlane(
304  const TIL_AdaptiveImage &src,
306  int planei) const;
307 
308 private:
309  float myThresholdSquared;
310 };
311 #endif
312 
313 #endif
virtual bool ownedBySingleton() const
SYS_FORCE_INLINE bool needsSquares() const
virtual void filterPlaneVirtual(const TIL_AdaptiveImage &src, TIL_Raster &dest, int planei, int plane_src_components) const =0
const GLdouble * v
Definition: glcorearb.h:837
TIL_PixelFilterT(bool needs_squares=false, bool vets_samples=false, bool needs_weights=false)
TIL_PixelFilterDebug(int level)
NOTE: This does not need its own plane's squares, just the adaptivity plane's weights.
int64 exint
Definition: SYS_Types.h:125
GLint level
Definition: glcorearb.h:108
bool ownedBySingleton() const override
This is the super-duper-class for all pixel filters in TIL.
#define UT_ASSERT_MSG(ZZ,...)
Definition: UT_Assert.h:159
static TIL_PixelFilterPower2Block theInstance
TIL_PixelFilter(bool needs_squares, bool vets_samples, bool needs_weights)
bool ownedBySingleton() const override
virtual ~TIL_PixelFilter()
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
SYS_FORCE_INLINE bool vetsSamples() const
TIL_PixelFilterBlurThreshold(float threshold)
static TIL_PixelFilterPixelLevel theInstance
bool ownedBySingleton() const override
static TIL_PixelFilterMinMax< IS_MAX > theInstance
~TIL_PixelFilterT() override
SYS_FORCE_INLINE bool needsWeights() const
#define const
Definition: zconf.h:214
bool ownedBySingleton() const override
static TIL_PixelFilterSampleCount theInstance
#define TIL_API
Definition: TIL_API.h:10
void combineSample(int ncomponents, exint nexisting_samples, float *existing, exint nnew_samples, const float *new_sample) const override
GLenum src
Definition: glcorearb.h:1793