Nori  24
consttexture.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/texture.h>
20 
21 NORI_NAMESPACE_BEGIN
22 
23 template <typename T>
24 class ConstantTexture : public Texture<T> {
25 public:
26  ConstantTexture(const PropertyList &props);
27 
28  virtual std::string toString() const override;
29 
30  virtual T eval(const Point2f & uv) override {
31  return m_value;
32  }
33 
34 protected:
35  T m_value;
36 };
37 
38 template <>
40  m_value = props.getFloat("value",0.f);
41 }
42 template <>
44  m_value = props.getColor("value",Color3f(0.f));
45 }
46 
47 
48 template <>
49 std::string ConstantTexture<float>::toString() const {
50  return tfm::format(
51  "ConstantTexture[ %f ]",
52  m_value);
53 }
54 
55 template <>
57  return tfm::format(
58  "ConstantTexture[ %s ]",
59  m_value.toString());
60 }
61 
62 NORI_REGISTER_TEMPLATED_CLASS(ConstantTexture, float, "constant_float")
63 NORI_REGISTER_TEMPLATED_CLASS(ConstantTexture, Color3f, "constant_color")
64 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
float getFloat(const std::string &name) const
Get a float 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