HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_Filter.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: UT_Filter.h ( UT Library, C++)
7  *
8  * COMMENTS: Circular symmetric separable filters. This class allows you to
9  * perform approximate filter weights given different filter
10  * kernels
11  *
12  * The lookup tables are valid for 0-1 and should be called with
13  * the square of the distance... The getWeight() methods can be
14  * used if given simple cartesian coordinates.
15  */
16 
17 #ifndef __UT_Filter__
18 #define __UT_Filter__
19 
20 #include "UT_API.h"
21 #include <SYS/SYS_Types.h>
22 #include <SYS/SYS_Math.h>
23 #include "UT_FilterType.h"
24 #include "UT_ValArray.h"
25 
26 class UT_Filter;
27 
28 // Build a convolution window for a given filter
30 public:
32  : myWeights(myBuffer)
33  , myStart(0)
34  , mySize(0)
35  , myCapacity(BUFSIZE)
36  , myVisible(1)
37  {
38  }
39 
41  {
42  if (myWeights != myBuffer)
43  delete [] myWeights;
44  }
45 
46  bool setWeights(const UT_Filter &filter, float center,
47  float radius, int res,
49 
50  // This should be called if houdini13 filtering is enabled
51  template <UT_FilterWrap>
52  bool setWeights(const UT_Filter &filter, float center,
53  float radius, int res);
54 
55  // A more efficient version of setWeights(). However, there seems to be an
56  // issue with computing the rounding when filtering. $RTM/texture seems to
57  // have a more "linear" result, but $RT/itools/stdin_stdout has an obvious
58  // shift in the image. So, this isn't quite ready for prime time.
59  template <UT_FilterWrap>
60  bool setWeightsFast(const UT_Filter &filter, float center,
61  float radius, int res);
62 
63 
64  void blendWithNextMip(int res, UT_FilterWrap mode,
65  float mipinterp);
66 
67  // Trim out zero weights. This is typically not done by default, but if
68  // you're reusing these weights a lot, you might consider trimming.
69  void trimWeights()
70  {
71  if (myWeights[0] == 0 || myWeights[mySize-1] == 0)
72  pruneZeroWeights();
73  }
74 
75  const float *getWeights() const { return myWeights; }
76  int getStart() const { return myStart; }
77  int getEnd() const { return myStart + mySize - 1; }
78  int getSize() const { return mySize; }
79  float getVisible() const { return myVisible; }
80 
81  void dump(const char *msg="") const;
82 
83 private:
84  void pruneZeroWeights();
85 
86  // Ensure we have enough space to fill the weights. Prefer to use the
87  // local buffer, since this allows the filter to operate without memory
88  // allocation.
89  template <bool COPY>
90  void resizeWeights(int prevsize=0)
91  {
92  if (mySize > myCapacity)
93  {
94  float *weights = myWeights;
95  myWeights = new float[mySize];
96  myCapacity = mySize;
97  if (COPY)
98  memcpy(myWeights, weights, prevsize*sizeof(float));
99  if (weights != myBuffer)
100  delete [] weights;
101  }
102  }
103 
104 private:
105  static const int BUFSIZE = 16;
106 
107  float myBuffer[BUFSIZE];
108  float *myWeights;
109  int myStart, mySize;
110  int myCapacity;
111  float myVisible;
112 };
113 
114 
116 {
117 public:
118  // Method to lookup the filter by name.
119  static UT_FilterType lookupFilter(const char *name);
120  static const char *getFilterName(UT_FilterType type);
121  static const char *getFilterLabel(UT_FilterType type);
122 
123  // Get a well known filter type
124  static UT_Filter *getFilter(UT_FilterType type);
125 
126  // Look up the filter wrap type given a string. If the type is unknown,
127  // return def.
128  static UT_FilterWrap lookupWrap(const char *keyword,
129  UT_FilterWrap def);
130 
131  // Get a custom filter kernel
132  static UT_Filter *getFilter(float (*evalfunc)(float, void *),
133  int size, int support = 2,
134  void *data = 0);
135 
136  static void releaseFilter(UT_Filter *filter);
137  void access() { myRefCount++; }
138 
139  /// Fill an array of weights. The @c center variable specifies the center
140  /// of the filter (in resolution space - not 0-1).
141  ///
142  /// For example, if you have a filter with a radius of 1.3 centered at
143  /// pixel 8.4, you should set:
144  /// - @c center = 8.4
145  /// - @c radius = 1.3
146  /// - @c size = floor(8.4+1.3) - floor(8.4-1.3) + 1 = 9-7+1 = 3
147  virtual void fillWeights(float umin, float radius,
148  float *weights, int size) const;
149 
150  // Compute average weight over the span l-r. The valid range for
151  // samples is -0.5F to 0.5F (i.e. a filter width of 1)
152  virtual float getWeight(float l, float r) const = 0;
153 
154  // Retrieve the filter area to the left of l
155  virtual float getArea(float l) const = 0;
156 
157  // Return the filter type
158  UT_FilterType getType() const { return myType; }
159 
160  // Get the filters desired support radius (i.e. 2 for gaussian)
161  float getSupport() const { return mySupport; }
162 
163 public:
164  virtual ~UT_Filter();
165 
166 protected:
167  UT_Filter() : myRefCount(0), myType(UT_FILTER_BOX) {}
168 
171  float mySupport;
172 };
173 
174 #endif
float getVisible() const
Definition: UT_Filter.h:79
int myRefCount
Definition: UT_Filter.h:169
int getEnd() const
Definition: UT_Filter.h:77
UT_FilterWrap
Definition: UT_FilterType.h:40
#define UT_API
Definition: UT_API.h:12
int getStart() const
Definition: UT_Filter.h:76
UT_FilterType
Definition: UT_FilterType.h:16
const float * getWeights() const
Definition: UT_Filter.h:75
void trimWeights()
Definition: UT_Filter.h:69
GLsizeiptr size
Definition: glcorearb.h:663
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
int getSize() const
Definition: UT_Filter.h:78
GLenum mode
Definition: glcorearb.h:98
UT_FilterType getType() const
Definition: UT_Filter.h:158
float getSupport() const
Definition: UT_Filter.h:161
UT_FilterType myType
Definition: UT_Filter.h:170
float mySupport
Definition: UT_Filter.h:171
void access()
Definition: UT_Filter.h:137
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
GLboolean r
Definition: glcorearb.h:1221
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296