Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
photon.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba 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  Mitsuba 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 #pragma once
20 #if !defined(__MITSUBA_RENDER_PHOTON_H_)
21 #define __MITSUBA_RENDER_PHOTON_H_
22 
24 #include <mitsuba/core/kdtree.h>
25 
26 /**
27  * \brief Should Mitsuba use a left-balanced photon map?
28  *
29  * This saves some memory, but at a noticeable cost in query
30  * performance. The default is to build an unbalanced
31  * photon map using the sliding midpoint rule.
32  */
33 #define MTS_PHOTONMAP_LEFT_BALANCED 0
34 
36 
37 /// Internal data record used by \ref Photon
38 struct PhotonData {
39 #if defined(SINGLE_PRECISION) && SPECTRUM_SAMPLES == 3
40  uint8_t power[4]; //!< Photon power stored in Greg Ward's RGBE format
41 #else
42  Spectrum power; //!< Accurate spectral photon power representation
43 #endif
44  uint8_t theta; //!< Discretized photon direction (\a theta component)
45  uint8_t phi; //!< Discretized photon direction (\a phi component)
46  uint8_t thetaN; //!< Discretized surface normal (\a theta component)
47  uint8_t phiN; //!< Discretized surface normal (\a phi component)
48  uint16_t depth; //!< Photon depth (number of preceding interactions)
49 };
50 
51 /** \brief Memory-efficient photon representation for use with
52  * \ref PointKDTree
53  *
54  * \ingroup librender
55  * \sa PhotonMap
56  */
58 #if MTS_PHOTONMAP_LEFT_BALANCED == 1
59  public LeftBalancedKDNode<Point, PhotonData> {
60 #else
62 #endif
63  friend class PhotonMap;
64 public:
65  /// Dummy constructor
66  inline Photon() { }
67 
68  /// Construct from a photon interaction
69  Photon(const Point &pos, const Normal &normal,
70  const Vector &dir, const Spectrum &power,
71  uint16_t depth);
72 
73  /// Unserialize from a binary data stream
74  Photon(Stream *stream);
75 
76  /// @}
77  // ======================================================================
78 
79  /// Return the depth (in # of interactions)
80  inline int getDepth() const {
81  return data.depth;
82  }
83 
84  /**
85  * Convert the photon direction from quantized spherical coordinates
86  * to a floating point vector value. Precomputation idea based on
87  * Jensen's implementation.
88  */
89  inline Vector getDirection() const {
90  return Vector(
91  m_cosPhi[data.phi] * m_sinTheta[data.theta],
92  m_sinPhi[data.phi] * m_sinTheta[data.theta],
93  m_cosTheta[data.theta]
94  );
95  }
96 
97  /**
98  * Convert the normal direction from quantized spherical coordinates
99  * to a floating point vector value.
100  */
101  inline Normal getNormal() const {
102  return Normal(
103  m_cosPhi[data.phiN] * m_sinTheta[data.thetaN],
104  m_sinPhi[data.phiN] * m_sinTheta[data.thetaN],
105  m_cosTheta[data.thetaN]
106  );
107  }
108 
109  /// Convert the photon power from RGBE to floating point
110  inline Spectrum getPower() const {
111 #if defined(SINGLE_PRECISION) && SPECTRUM_SAMPLES == 3
112  Spectrum result;
113  result.fromRGBE(data.power);
114  return result;
115 #else
116  return data.power;
117 #endif
118  }
119 
120  /// Serialize to a binary data stream
121  void serialize(Stream *stream) const;
122 
123  /// Return a string representation (for debugging)
124  std::string toString() const;
125 protected:
126  // ======================================================================
127  /// @{ \name Precomputed lookup tables
128  // ======================================================================
129 
130  static Float m_cosTheta[256];
131  static Float m_sinTheta[256];
132  static Float m_cosPhi[256];
133  static Float m_sinPhi[256];
134  static Float m_expTable[256];
135  static bool m_precompTableReady;
136 
137  /// @}
138  // ======================================================================
139 
140  /// Initialize the precomputed lookup tables
141  static bool createPrecompTables();
142 };
143 
145 
146 #endif /* __MITSUBA_RENDER_PHOTON_H_ */
static bool m_precompTableReady
Definition: photon.h:135
uint8_t phiN
Discretized surface normal (phi component)
Definition: photon.h:47
Three-dimensional normal data structure.
Definition: normal.h:39
Left-balanced kd-tree node for use with PointKDTree.
Definition: kdtree.h:128
TVector3< Float > Vector
Definition: fwd.h:113
Spectrum power
Accurate spectral photon power representation.
Definition: photon.h:42
Photon()
Dummy constructor.
Definition: photon.h:66
Internal data record used by Photon.
Definition: photon.h:38
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Spectrum getPower() const
Convert the photon power from RGBE to floating point.
Definition: photon.h:110
void fromRGBE(const uint8_t rgbe[4], EConversionIntent intent=EIlluminant)
Convert linear RGBE colors into a plausible spectral power distribution.
Abstract seekable stream class.
Definition: stream.h:58
Implementation of the photon map data structure.
Definition: photonmap.h:34
Memory-efficient photon representation for use with PointKDTree.
Definition: photon.h:57
Normal getNormal() const
Definition: photon.h:101
int getDepth() const
Return the depth (in # of interactions)
Definition: photon.h:80
Definition: fwd.h:96
uint16_t depth
Photon depth (number of preceding interactions)
Definition: photon.h:48
uint8_t phi
Discretized photon direction (phi component)
Definition: photon.h:45
Vector getDirection() const
Definition: photon.h:89
Definition: fwd.h:100
uint8_t thetaN
Discretized surface normal (theta component)
Definition: photon.h:46
#define MTS_EXPORT_RENDER
Definition: platform.h:109
Discrete spectral power distribution based on a number of wavelength bins over the 360-830 nm range...
Definition: spectrum.h:663
uint8_t theta
Discretized photon direction (theta component)
Definition: photon.h:44
#define MTS_NAMESPACE_END
Definition: platform.h:138