Nori  23
photon.h
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 #if !defined(__NORI_PHOTON_H)
20 #define __NORI_PHOTON_H
21 
22 #include <nori/kdtree.h>
23 #include <nori/color.h>
24 
25 NORI_NAMESPACE_BEGIN
26 
28 struct PhotonData {
29  uint8_t rgbe[4];
30  uint8_t theta;
31  uint8_t phi;
32 
34  PhotonData() { }
35 
37  PhotonData(const Vector3f &dir, const Color3f &power);
38 
45  return Vector3f(
46  m_cosPhi[phi] * m_sinTheta[theta],
47  m_sinPhi[phi] * m_sinTheta[theta],
48  m_cosTheta[theta]
49  );
50  }
51 
53  Color3f getPower() const {
54  return Color3f(rgbe[0], rgbe[1], rgbe[2]) * m_expTable[rgbe[3]];
55  }
56 protected:
57  // ======================================================================
59  // ======================================================================
60 
61  static float m_cosTheta[256];
62  static float m_sinTheta[256];
63  static float m_cosPhi[256];
64  static float m_sinPhi[256];
65  static float m_expTable[256];
66  static bool m_precompTableReady;
67 
69  // ======================================================================
70 
72  static bool initialize();
73 };
74 
76 struct Photon : public GenericKDTreeNode<Point3f, PhotonData> {
77 public:
79  Photon() { }
80 
82  Photon(const Point3f &pos, const Vector3f &dir, const Color3f &power)
83  : GenericKDTreeNode(pos, PhotonData(dir, power)) { }
84 
85  Vector3f getDirection() const { return data.getDirection(); }
86  Color3f getPower() const { return data.getPower(); }
87 };
88 
89 NORI_NAMESPACE_END
90 
91 #endif /* __NORI_PHOTON_H */
Represents a linear RGB color value.
Definition: color.h:29
Simple kd-tree node data structure for use with PointKDTree.
Definition: kdtree.h:42
Stores the direction and power of a photon as "payload" of a generic kd-tree node (see kdtree....
Definition: photon.h:28
uint8_t rgbe[4]
Photon power stored in Greg Ward's RGBE format.
Definition: photon.h:29
Vector3f getDirection() const
Definition: photon.h:44
PhotonData()
Dummy constructor.
Definition: photon.h:34
uint8_t theta
Discretized photon direction (theta component)
Definition: photon.h:30
Color3f getPower() const
Convert the photon power from RGBE to floating point.
Definition: photon.h:53
static bool initialize()
Initialize the precomputed lookup tables.
Definition: photon.cpp:30
uint8_t phi
Discretized photon direction (phi component)
Definition: photon.h:31
A Photon which also doubles as a kd-tree node for use with PointKDTree.
Definition: photon.h:76
Photon()
Dummy constructor.
Definition: photon.h:79
Photon(const Point3f &pos, const Vector3f &dir, const Color3f &power)
Construct from a photon interaction.
Definition: photon.h:82