Nori  24
rfilter.cpp
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Wenzel Jakob
5 
6  Nori is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Nori is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <nori/rfilter.h>
20 
21 NORI_NAMESPACE_BEGIN
22 
29 public:
30  GaussianFilter(const PropertyList &propList) {
31  /* Half filter size */
32  m_radius = propList.getFloat("radius", 2.0f);
33  /* Standard deviation of the Gaussian */
34  m_stddev = propList.getFloat("stddev", 0.5f);
35  }
36 
37  float eval(float x) const {
38  float alpha = -1.0f / (2.0f * m_stddev*m_stddev);
39  return std::max(0.0f,
40  std::exp(alpha * x * x) -
41  std::exp(alpha * m_radius * m_radius));
42  }
43 
44  virtual std::string toString() const override {
45  return tfm::format("GaussianFilter[radius=%f, stddev=%f]", m_radius, m_stddev);
46  }
47 protected:
48  float m_stddev;
49 };
50 
58 public:
59  MitchellNetravaliFilter(const PropertyList &propList) {
60  /* Filter size in pixels */
61  m_radius = propList.getFloat("radius", 2.0f);
62  /* B parameter from the paper */
63  m_B = propList.getFloat("B", 1.0f / 3.0f);
64  /* C parameter from the paper */
65  m_C = propList.getFloat("C", 1.0f / 3.0f);
66  }
67 
68  float eval(float x) const {
69  x = std::abs(2.0f * x / m_radius);
70  float x2 = x*x, x3 = x2*x;
71 
72  if (x < 1) {
73  return 1.0f/6.0f * ((12-9*m_B-6*m_C)*x3
74  + (-18+12*m_B+6*m_C) * x2 + (6-2*m_B));
75  } else if (x < 2) {
76  return 1.0f/6.0f * ((-m_B-6*m_C)*x3 + (6*m_B+30*m_C) * x2
77  + (-12*m_B-48*m_C)*x + (8*m_B + 24*m_C));
78  } else {
79  return 0.0f;
80  }
81  }
82 
83  virtual std::string toString() const override {
84  return tfm::format("MitchellNetravaliFilter[radius=%f, B=%f, C=%f]", m_radius, m_B, m_C);
85  }
86 protected:
87  float m_B, m_C;
88 };
89 
92 public:
93  TentFilter(const PropertyList &) {
94  m_radius = 1.0f;
95  }
96 
97  float eval(float x) const {
98  return std::max(0.0f, 1.0f - std::abs(x));
99  }
100 
101  virtual std::string toString() const override {
102  return "TentFilter[]";
103  }
104 };
105 
108 public:
109  BoxFilter(const PropertyList &) {
110  m_radius = 0.5f;
111  }
112 
113  float eval(float) const {
114  return 1.0f;
115  }
116 
117  virtual std::string toString() const override {
118  return "BoxFilter[]";
119  }
120 };
121 
122 NORI_REGISTER_CLASS(GaussianFilter, "gaussian");
123 NORI_REGISTER_CLASS(MitchellNetravaliFilter, "mitchell");
124 NORI_REGISTER_CLASS(TentFilter, "tent");
125 NORI_REGISTER_CLASS(BoxFilter, "box");
126 
127 NORI_NAMESPACE_END
Box filter – fastest, but prone to aliasing.
Definition: rfilter.cpp:107
virtual std::string toString() const override
Return a brief string summary of the instance (for debugging purposes)
Definition: rfilter.cpp:117
float eval(float) const
Evaluate the filter function.
Definition: rfilter.cpp:113
float eval(float x) const
Evaluate the filter function.
Definition: rfilter.cpp:37
virtual std::string toString() const override
Return a brief string summary of the instance (for debugging purposes)
Definition: rfilter.cpp:44
float eval(float x) const
Evaluate the filter function.
Definition: rfilter.cpp:68
virtual std::string toString() const override
Return a brief string summary of the instance (for debugging purposes)
Definition: rfilter.cpp:83
This is an associative container used to supply the constructors of NoriObject subclasses with parame...
Definition: proplist.h:32
float getFloat(const std::string &name) const
Get a float property, and throw an exception if it does not exist.
Generic radially symmetric image reconstruction filter.
Definition: rfilter.h:41
Tent filter.
Definition: rfilter.cpp:91
virtual std::string toString() const override
Return a brief string summary of the instance (for debugging purposes)
Definition: rfilter.cpp:101
float eval(float x) const
Evaluate the filter function.
Definition: rfilter.cpp:97