Nori  23
checkerboard.cpp
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Romain Prévost
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/object.h>
20 #include <nori/texture.h>
21 
22 NORI_NAMESPACE_BEGIN
23 
24 template <typename T>
25 class Checkerboard : public Texture<T> {
26 public:
27  Checkerboard(const PropertyList &props);
28 
29  virtual std::string toString() const override;
30 
31  virtual T eval(const Point2f & uv) override {
32  /* to be implemented */
33  return m_value1;
34  }
35 
36 protected:
37  T m_value1;
38  T m_value2;
39 
40  Point2f m_delta;
41  Vector2f m_scale;
42 };
43 
44 template <>
46  m_delta = props.getPoint2("delta", Point2f(0));
47  m_scale = props.getVector2("scale", Vector2f(1));
48  m_value1 = props.getFloat("value1", 0.f);
49  m_value2 = props.getFloat("value2", 1.f);
50 }
51 
52 template <>
54  m_delta = props.getPoint2("delta", Point2f(0));
55  m_scale = props.getVector2("scale", Vector2f(1));
56  m_value1 = props.getColor("value1", Color3f(0));
57  m_value2 = props.getColor("value2", Color3f(1));
58 }
59 
60 
61 template <>
62 std::string Checkerboard<float>::toString() const {
63  return tfm::format(
64  "Checkerboard[\n"
65  " delta = %s,\n"
66  " scale = %s,\n"
67  " value1 = %f,\n"
68  " value2 = %f,\n"
69  "]",
70  m_delta.toString(),
71  m_scale.toString(),
72  m_value1,
73  m_value2
74  );
75 }
76 
77 template <>
78 std::string Checkerboard<Color3f>::toString() const {
79  return tfm::format(
80  "Checkerboard[\n"
81  " delta = %s,\n"
82  " scale = %s,\n"
83  " tex1 = %s,\n"
84  " tex2 = %s,\n"
85  "]",
86  m_delta.toString(),
87  m_scale.toString(),
88  m_value1.toString(),
89  m_value2.toString()
90  );
91 }
92 
93 NORI_REGISTER_TEMPLATED_CLASS(Checkerboard, float, "checkerboard_float")
94 NORI_REGISTER_TEMPLATED_CLASS(Checkerboard, Color3f, "checkerboard_color")
95 NORI_NAMESPACE_END
virtual std::string toString() const override
Return a brief string summary of the instance (for debugging purposes)
This is an associative container used to supply the constructors of NoriObject subclasses with parame...
Definition: proplist.h:32
Point2f getPoint2(const std::string &name) const
Get a point property, and throw an exception if it does not exist.
float getFloat(const std::string &name) const
Get a float property, and throw an exception if it does not exist.
Vector2f getVector2(const std::string &name) const
Get a vector property, and throw an exception if it does not exist.
Color3f getColor(const std::string &name) const
Get a color property, and throw an exception if it does not exist.
Superclass of all texture.
Definition: texture.h:30
Represents a linear RGB color value.
Definition: color.h:29