HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filter.h
Go to the documentation of this file.
1 /*
2  Copyright 2008 Larry Gritz and the other authors and contributors.
3  All Rights Reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the software's owners nor the names of its
14  contributors may be used to endorse or promote products derived from
15  this software without specific prior written permission.
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  (This is the Modified BSD License)
29 */
30 
31 
32 #pragma once
33 
34 #include <OpenImageIO/export.h>
37 
38 
40 
41 /// Quick structure that describes a filter.
42 ///
44 public:
45  const char* name; ///< name of the filter
46  int dim; ///< dimensionality: 1 or 2
47  float width; ///< Recommended width or window
48  bool fixedwidth; ///< Is the width the only one that makes sense?
49  bool scalable; ///< Is it scalable (otherwise, the width is a window)?
50  bool separable; ///< Is it separable? (only matters if dim==2)
51 };
52 
53 
54 
55 /// Filter1D is the abstract data type for a 1D filter.
56 /// The filters are NOT expected to have their results normalized.
58 public:
59  Filter1D(float width)
60  : m_w(width)
61  {
62  }
63  virtual ~Filter1D(void) {};
64 
65  /// Get the width of the filter
66  float width(void) const { return m_w; }
67 
68  /// Evalutate the filter at an x position (relative to filter center)
69  virtual float operator()(float x) const = 0;
70 
71  /// Return the name of the filter, e.g., "box", "gaussian"
72  virtual string_view name(void) const = 0;
73 
74  /// This static function allocates and returns an instance of the
75  /// specific filter implementation for the name you provide.
76  /// Example use:
77  /// Filter1D *myfilt = Filter1::create ("box", 1);
78  /// The caller is responsible for deleting it when it's done.
79  /// If the name is not recognized, return NULL.
80  static Filter1D* create(string_view filtername, float width);
81 
82  /// Destroy a filter that was created with create().
83  static void destroy(Filter1D* filt);
84 
85  /// Get the number of filters supported.
86  static int num_filters();
87  /// Get the info for a particular index (0..num_filters()-1).
88  static void get_filterdesc(int filternum, FilterDesc* filterdesc);
89  static const FilterDesc& get_filterdesc(int filternum);
90 
91 protected:
92  float m_w;
93 };
94 
95 
96 
97 /// Filter2D is the abstract data type for a 2D filter.
98 /// The filters are NOT expected to have their results normalized.
100 public:
101  Filter2D(float width, float height)
102  : m_w(width)
103  , m_h(height)
104  {
105  }
106  virtual ~Filter2D(void) {};
107 
108  /// Get the width of the filter
109  float width(void) const { return m_w; }
110  /// Get the height of the filter
111  float height(void) const { return m_h; }
112 
113  /// Is the filter separable?
114  ///
115  virtual bool separable() const { return false; }
116 
117  /// Evalutate the filter at an x and y position (relative to filter
118  /// center).
119  virtual float operator()(float x, float y) const = 0;
120 
121  /// Evaluate just the horizontal filter (if separable; for non-separable
122  /// it just evaluates at (x,0).
123  virtual float xfilt(float x) const { return (*this)(x, 0.0f); }
124 
125  /// Evaluate just the vertical filter (if separable; for non-separable
126  /// it just evaluates at (0,y).
127  virtual float yfilt(float y) const { return (*this)(0.0f, y); }
128 
129  /// Return the name of the filter, e.g., "box", "gaussian"
130  virtual string_view name(void) const = 0;
131 
132  /// This static function allocates and returns an instance of the
133  /// specific filter implementation for the name you provide.
134  /// Example use:
135  /// Filter2D *myfilt = Filter2::create ("box", 1, 1);
136  /// The caller is responsible for deleting it when it's done.
137  /// If the name is not recognized, return NULL.
138  static Filter2D* create(string_view filtername, float width, float height);
139 
140  /// Destroy a filter that was created with create().
141  static void destroy(Filter2D* filt);
142 
143  /// Get the number of filters supported.
144  static int num_filters();
145  /// Get the info for a particular index (0..num_filters()-1).
146  static void get_filterdesc(int filternum, FilterDesc* filterdesc);
147  static const FilterDesc& get_filterdesc(int filternum);
148 
149 protected:
150  float m_w, m_h;
151 };
152 
153 
float m_w
Definition: filter.h:92
bool fixedwidth
Is the width the only one that makes sense?
Definition: filter.h:48
GLuint const GLchar * name
Definition: glew.h:1814
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1252
float height(void) const
Get the height of the filter.
Definition: filter.h:111
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1252
int dim
dimensionality: 1 or 2
Definition: filter.h:46
bool scalable
Is it scalable (otherwise, the width is a window)?
Definition: filter.h:49
bool separable
Is it separable? (only matters if dim==2)
Definition: filter.h:50
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
virtual bool separable() const
Definition: filter.h:115
float width(void) const
Get the width of the filter.
Definition: filter.h:66
float width(void) const
Get the width of the filter.
Definition: filter.h:109
virtual float yfilt(float y) const
Definition: filter.h:127
const char * name
name of the filter
Definition: filter.h:45
float width
Recommended width or window.
Definition: filter.h:47
virtual float xfilt(float x) const
Definition: filter.h:123
virtual ~Filter1D(void)
Definition: filter.h:63
virtual ~Filter2D(void)
Definition: filter.h:106
Filter1D(float width)
Definition: filter.h:59
Filter2D(float width, float height)
Definition: filter.h:101
float m_w
Definition: filter.h:150
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:66
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:65
#define OIIO_API
Definition: export.h:91