Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
medium.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_MEDIUM_H_)
21 #define __MITSUBA_RENDER_MEDIUM_H_
22 
23 #include <mitsuba/core/netobject.h>
24 #include <mitsuba/core/aabb.h>
25 
27 /**
28  * \brief Data record for sampling a point on the in-scattering
29  * integral of the RTE
30  *
31  * \sa Medium::sampleDistance()
32  * \ingroup librender
33  */
35 public:
36 
37  /// Traveled distance
39 
40  /// Location of the scattering interaction
42 
43  /// Time value associated with the medium scattering event
45 
46  /// Local particle orientation at \ref p
48 
49  /**
50  * \brief Specifies the transmittance along the segment [mint, t]
51  *
52  * When sampling a distance fails, this contains the
53  * transmittance along the whole ray segment [mint, maxDist].
54  */
56 
57  /// The medium's absorption coefficient at \ref p
59 
60  /// The medium's scattering coefficient at \ref p
62 
63  /// Records the probability density of sampling a medium interaction at p
65 
66  /**
67  * \brief Records the probability density of sampling a medium
68  * interaction in the reverse direction
69  *
70  * This is essentially the density of obtained by calling \ref sampleDistance,
71  * but starting at \c p and stopping at \c ray.o. These probabilities
72  * are important for bidirectional methods.
73  */
75 
76  /**
77  * When the \ref Medium::sampleDistance() is successful, this function
78  * returns the probability of \a not having generated a medium interaction
79  * until \ref t. Otherwise, it records the probability of
80  * not generating any interactions in the whole interval [mint, maxt].
81  * This probability is assumed to be symmetric with respect to
82  * sampling from the other direction, which is why there is no
83  * \c pdfFailureRev field.
84  */
86 
87  /// Pointer to the associated medium
88  const Medium *medium;
89 
90 public:
91  inline MediumSamplingRecord() : medium(NULL) { }
92 
93  /// Return a pointer to the phase function
94  inline const PhaseFunction *getPhaseFunction() const;
95 
96  /// Return a string representation
97  std::string toString() const;
98 };
99 
100 /** \brief Abstract participating medium
101  * \ingroup librender
102  */
104 public:
105  // =============================================================
106  //! @{ \name Medium sampling strategy
107  // =============================================================
108 
109  /**
110  * \brief Sample a distance along the ray segment [mint, maxt]
111  *
112  * Should ideally importance sample with respect to the transmittance.
113  * It is assumed that the ray has a normalized direction value.
114  *
115  * \param ray Ray, along which a distance should be sampled
116  * \param mRec Medium sampling record to be filled with the result
117  * \return \c false if the maximum distance was exceeded, or if
118  * no interaction inside the medium could be sampled.
119  */
120  virtual bool sampleDistance(const Ray &ray,
121  MediumSamplingRecord &mRec, Sampler *sampler) const = 0;
122 
123  /**
124  * \brief Compute the 1D density of sampling distance \a ray.maxt
125  * along the ray using the sampling strategy implemented by
126  * \a sampleDistance.
127  *
128  * The function computes the continuous densities in the case of
129  * a successful \ref sampleDistance() invocation (in both directions),
130  * as well as the Dirac delta density associated with a failure.
131  * For convenience, it also stores the transmittance along the
132  * supplied ray segment within \a mRec.
133  */
134  virtual void eval(const Ray &ray,
135  MediumSamplingRecord &mRec) const = 0;
136 
137  //! @}
138  // =============================================================
139 
140  // =============================================================
141  //! @{ \name Functions for querying the medium
142  // =============================================================
143 
144  /**
145  * \brief Compute the transmittance along a ray segment
146  *
147  * Computes the transmittance along a ray segment
148  * [mint, maxt] associated with the ray. It is assumed
149  * that the ray has a normalized direction value.
150  */
151  virtual Spectrum evalTransmittance(const Ray &ray,
152  Sampler *sampler = NULL) const = 0;
153 
154  /// Return the phase function of this medium
155  inline const PhaseFunction *getPhaseFunction() const { return m_phaseFunction.get(); }
156 
157  /// Determine whether the medium is homogeneous
158  virtual bool isHomogeneous() const = 0;
159 
160  /// For homogeneous media: return the absorption coefficient
161  inline const Spectrum &getSigmaA() const { return m_sigmaA; }
162 
163  /// For homogeneous media: return the scattering coefficient
164  inline const Spectrum &getSigmaS() const { return m_sigmaS; }
165 
166  /// For homogeneous media: return the extinction coefficient
167  inline const Spectrum &getSigmaT() const { return m_sigmaT; }
168 
169  //! @}
170  // =============================================================
171 
172  // =============================================================
173  //! @{ \name Miscellaneous
174  // =============================================================
175 
176  /** \brief Configure the object (called \a once after construction
177  and addition of all child \ref ConfigurableObject instances). */
178  virtual void configure();
179 
180  /// Serialize this medium to a stream
181  virtual void serialize(Stream *stream, InstanceManager *manager) const;
182 
183  /// Add a child ConfigurableObject
184  virtual void addChild(const std::string &name, ConfigurableObject *child);
185  /// Add an unnamed child
186  inline void addChild(ConfigurableObject *child) { addChild("", child); }
187 
188  /// Return a string representation
189  virtual std::string toString() const = 0;
190 
191  //! @}
192  // =============================================================
193 
195 protected:
196  /// Create a new participating medium instance
197  Medium(const Properties &props);
198 
199  /// Unserialize a participating medium
200  Medium(Stream *stream, InstanceManager *manager);
201 
202  /// Virtual destructor
203  virtual ~Medium() { }
204 protected:
209 };
210 
212 
213 #endif /* __MITSUBA_RENDER_MEDIUM_H_ */
Float t
Traveled distance.
Definition: medium.h:38
const Medium * medium
Pointer to the associated medium.
Definition: medium.h:88
Abstract participating medium.
Definition: medium.h:103
Float pdfSuccess
Records the probability density of sampling a medium interaction at p.
Definition: medium.h:64
Generic serializable object, which supports construction from a Properties instance.
Definition: cobject.h:40
Spectrum m_sigmaS
Definition: medium.h:207
const Spectrum & getSigmaA() const
For homogeneous media: return the absorption coefficient.
Definition: medium.h:161
Float pdfFailure
Definition: medium.h:85
Base class of all sample generators.
Definition: sampler.h:66
Spectrum m_sigmaT
Definition: medium.h:208
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
MediumSamplingRecord()
Definition: medium.h:91
Spectrum sigmaA
The medium&#39;s absorption coefficient at p.
Definition: medium.h:58
Vector orientation
Local particle orientation at p.
Definition: medium.h:47
Float pdfSuccessRev
Records the probability density of sampling a medium interaction in the reverse direction.
Definition: medium.h:74
Spectrum m_sigmaA
Definition: medium.h:206
const Spectrum & getSigmaS() const
For homogeneous media: return the scattering coefficient.
Definition: medium.h:164
Spectrum sigmaS
The medium&#39;s scattering coefficient at p.
Definition: medium.h:61
Data record for sampling a point on the in-scattering integral of the RTE.
Definition: medium.h:34
virtual void addChild(const std::string &name, ConfigurableObject *child)
Add a child (default implementation throws an error)
void addChild(ConfigurableObject *child)
Add an unnamed child.
Definition: medium.h:186
Abstract seekable stream class.
Definition: stream.h:58
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
const Spectrum & getSigmaT() const
For homogeneous media: return the extinction coefficient.
Definition: medium.h:167
Point p
Location of the scattering interaction.
Definition: medium.h:41
virtual void configure()
Configure the object (called once after construction and addition of all child ConfigurableObject ins...
Reference counting helper.
Definition: ref.h:40
Abstract phase function.
Definition: phase.h:117
Definition: fwd.h:65
Float time
Time value associated with the medium scattering event.
Definition: medium.h:44
virtual void serialize(Stream *stream, InstanceManager *manager) const
Serialize this object to a stream.
Definition: fwd.h:96
const PhaseFunction * getPhaseFunction() const
Return the phase function of this medium.
Definition: medium.h:155
Abstract interface for objects that reference shared network resources.
Definition: netobject.h:40
Spectrum transmittance
Specifies the transmittance along the segment [mint, t].
Definition: medium.h:55
Associative parameter map for constructing subclasses of ConfigurableObject.
Definition: properties.h:46
Definition: fwd.h:100
ref< PhaseFunction > m_phaseFunction
Definition: medium.h:205
Coordinates the serialization and unserialization of object graphs.
Definition: serialization.h:65
#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
virtual std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
#define MTS_NAMESPACE_END
Definition: platform.h:138