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
<>
39
ConstantTexture<float>::ConstantTexture
(
const
PropertyList
&props) {
40
m_value = props.
getFloat
(
"value"
,0.f);
41
}
42
template
<>
43
ConstantTexture<Color3f>::ConstantTexture
(
const
PropertyList
&props) {
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
<>
56
std::string
ConstantTexture<Color3f>::toString
()
const
{
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
ConstantTexture
Definition:
consttexture.cpp:24
ConstantTexture::toString
virtual std::string toString() const override
Return a brief string summary of the instance (for debugging purposes)
PropertyList
This is an associative container used to supply the constructors of NoriObject subclasses with parame...
Definition:
proplist.h:32
PropertyList::getFloat
float getFloat(const std::string &name) const
Get a float property, and throw an exception if it does not exist.
PropertyList::getColor
Color3f getColor(const std::string &name) const
Get a color property, and throw an exception if it does not exist.
Texture
Superclass of all texture.
Definition:
texture.h:30
Color3f
Represents a linear RGB color value.
Definition:
color.h:29
TPoint< float, 2 >
src
consttexture.cpp
Generated by
1.9.1