HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filter.h
Go to the documentation of this file.
1 // Copyright 2008-present Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: BSD-3-Clause
3 // https://github.com/OpenImageIO/oiio
4 
5 
6 #pragma once
7 
8 #include <OpenImageIO/export.h>
11 
12 
14 
15 /// Quick structure that describes a filter.
16 ///
18 public:
19  const char* name; ///< name of the filter
20  int dim; ///< dimensionality: 1 or 2
21  float width; ///< Recommended width or window
22  bool fixedwidth; ///< Is the width the only one that makes sense?
23  bool scalable; ///< Is it scalable (otherwise, the width is a window)?
24  bool separable; ///< Is it separable? (only matters if dim==2)
25 };
26 
27 
28 
29 /// Filter1D is the abstract data type for a 1D filter.
30 /// The filters are NOT expected to have their results normalized.
32 public:
33  Filter1D(float width)
34  : m_w(width)
35  {
36  }
37  virtual ~Filter1D(void) {};
38 
39  /// Get the width of the filter
40  float width(void) const { return m_w; }
41 
42  /// Evaluate the filter at an x position (relative to filter center)
43  virtual float operator()(float x) const = 0;
44 
45  /// Return the name of the filter, e.g., "box", "gaussian"
46  virtual string_view name(void) const = 0;
47 
48  /// This static function allocates and returns an instance of the
49  /// specific filter implementation for the name you provide.
50  /// Example use:
51  /// Filter1D *myfilt = Filter1::create ("box", 1);
52  /// The caller is responsible for deleting it when it's done.
53  /// If the name is not recognized, return NULL.
54  static Filter1D* create(string_view filtername, float width);
55 
56  /// Destroy a filter that was created with create().
57  static void destroy(Filter1D* filt);
58 
59  /// Get the number of filters supported.
60  static int num_filters();
61  /// Get the info for a particular index (0..num_filters()-1).
62  static void get_filterdesc(int filternum, FilterDesc* filterdesc);
63  static const FilterDesc& get_filterdesc(int filternum);
64 
65 protected:
66  float m_w;
67 };
68 
69 
70 
71 /// Filter2D is the abstract data type for a 2D filter.
72 /// The filters are NOT expected to have their results normalized.
74 public:
75  Filter2D(float width, float height)
76  : m_w(width)
77  , m_h(height)
78  {
79  }
80  virtual ~Filter2D(void) {};
81 
82  /// Get the width of the filter
83  float width(void) const { return m_w; }
84  /// Get the height of the filter
85  float height(void) const { return m_h; }
86 
87  /// Is the filter separable?
88  ///
89  virtual bool separable() const { return false; }
90 
91  /// Evaluate the filter at an x and y position (relative to filter
92  /// center).
93  virtual float operator()(float x, float y) const = 0;
94 
95  /// Evaluate just the horizontal filter (if separable; for non-separable
96  /// it just evaluates at (x,0).
97  virtual float xfilt(float x) const { return (*this)(x, 0.0f); }
98 
99  /// Evaluate just the vertical filter (if separable; for non-separable
100  /// it just evaluates at (0,y).
101  virtual float yfilt(float y) const { return (*this)(0.0f, y); }
102 
103  /// Return the name of the filter, e.g., "box", "gaussian"
104  virtual string_view name(void) const = 0;
105 
106  /// This static function allocates and returns an instance of the
107  /// specific filter implementation for the name you provide.
108  /// Example use:
109  /// Filter2D *myfilt = Filter2::create ("box", 1, 1);
110  /// The caller is responsible for deleting it when it's done.
111  /// If the name is not recognized, return NULL.
112  static Filter2D* create(string_view filtername, float width, float height);
113 
114  /// Destroy a filter that was created with create().
115  static void destroy(Filter2D* filt);
116 
117  /// Get the number of filters supported.
118  static int num_filters();
119  /// Get the info for a particular index (0..num_filters()-1).
120  static void get_filterdesc(int filternum, FilterDesc* filterdesc);
121  static const FilterDesc& get_filterdesc(int filternum);
122 
123 protected:
124  float m_w, m_h;
125 };
126 
127 
float m_w
Definition: filter.h:66
bool fixedwidth
Is the width the only one that makes sense?
Definition: filter.h:22
float height(void) const
Get the height of the filter.
Definition: filter.h:85
GLint y
Definition: glcorearb.h:103
int dim
dimensionality: 1 or 2
Definition: filter.h:20
bool scalable
Is it scalable (otherwise, the width is a window)?
Definition: filter.h:23
#define OIIO_UTIL_API
Definition: export.h:71
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
bool separable
Is it separable? (only matters if dim==2)
Definition: filter.h:24
virtual bool separable() const
Definition: filter.h:89
float width(void) const
Get the width of the filter.
Definition: filter.h:40
float width(void) const
Get the width of the filter.
Definition: filter.h:83
GLint GLenum GLint x
Definition: glcorearb.h:409
virtual float yfilt(float y) const
Definition: filter.h:101
const char * name
name of the filter
Definition: filter.h:19
float width
Recommended width or window.
Definition: filter.h:21
virtual float xfilt(float x) const
Definition: filter.h:97
virtual ~Filter1D(void)
Definition: filter.h:37
virtual ~Filter2D(void)
Definition: filter.h:80
Filter1D(float width)
Definition: filter.h:33
Filter2D(float width, float height)
Definition: filter.h:75
GLint GLsizei width
Definition: glcorearb.h:103
float m_w
Definition: filter.h:124
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:94
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:93