Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
common.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_COMMON_H_)
21 #define __MITSUBA_RENDER_COMMON_H_
22 
23 #include <mitsuba/core/ray.h>
24 
26 
27 /**
28  * \brief Specifies the transport mode when sampling or
29  * evaluating a scattering function
30  *
31  * \ingroup librender
32  */
34  /* Note to self: do not change these enumeration
35  values, some code depends on them. */
36 
37  /// Radiance transport
38  ERadiance = 0,
39  /// Importance transport
41  /// Specifies the number of supported transport modes
43 };
44 
45 /**
46  * \brief A list of measures that are associated with various sampling
47  * methods in Mitsuba.
48  *
49  * Every now and then, sampling densities consist of a sum of several terms
50  * defined on spaces that have different associated measures. In this case,
51  * one of the constants in \ref EMeasure can be specified to clarify the
52  * component in question when performing query operations.
53  *
54  * \ingroup librender
55  */
56 enum EMeasure {
57  /// Invalid measure
59  /// Solid angle measure
61  /// Length measure
62  ELength = 2,
63  /// Area measure
64  EArea = 3,
65  /// Discrete measure
67 };
68 
69 /**
70  * \brief Generic sampling record for positions
71  *
72  * This sampling record is used to implement techniques that draw a position
73  * from a point, line, surface, or volume domain in 3D and furthermore provide
74  * auxilary information about the sample.
75  *
76  * Apart from returning the position and (optionally) the surface normal, the
77  * responsible sampling method must annotate the record with the
78  * associated probability density and measure.
79  *
80  * \ingroup librender
81  */
83 public:
84  /// Sampled position
86 
87  /// Associated time value
89 
90  /// Sampled surface normal (if applicable)
92 
93  /// Probability density at the sample
95 
96  /**
97  * \brief Denotes the measure associated with the sample.
98  *
99  * This is necessary to deal with quantities that are defined on
100  * unusual spaces, e.g. areas that have collapsed to a point
101  * or a line.
102  */
104 
105  /**
106  * \brief Optional: 2D sample position associated with the record
107  *
108  * In some uses of this record, a sampled position may be associated
109  * with an important 2D quantity, such as the texture coordinates on
110  * a triangle mesh or a position on the aperture of a sensor. When
111  * applicable, such positions are stored in the \c uv attribute.
112  */
114 
115  /**
116  * \brief Optional: Pointer to an associated object
117  *
118  * In some uses of this record, sampling a position also involves
119  * choosing one of several objects (shapes, emitters, ..) on which
120  * the position lies. In that case, the \c object attribute stores
121  * a pointer to this object.
122  */
124 public:
125  /// Create an invalid position sampling record
127 
128  /**
129  * \brief Create a new position sampling record that can be
130  * passed e.g. to \ref Shape::samplePosition
131  *
132  * \param time
133  * Specifies the time that should be associated with the
134  * position sample. This only matters when things are in motion
135  */
136  inline PositionSamplingRecord(Float time) : time(time),
137  uv(0.0f), object(NULL) { }
138 
139  /**
140  * \brief Create a position sampling record
141  * from a surface intersection
142  *
143  * This is useful to determine the hypothetical sampling
144  * density on a surface after hitting it using standard
145  * ray tracing. This happens for instance in path tracing
146  * with multiple importance sampling.
147  */
148  inline PositionSamplingRecord(const Intersection &its,
149  EMeasure measure = EArea);
150 
151  /// Return a human-readable description of the record
152  std::string toString() const;
153 };
154 
155 /**
156  * \brief Generic sampling record for directions
157  *
158  * This sampling record is used to implement techniques that randomly draw a
159  * unit vector from a subset of the sphere and furthermore provide
160  * auxilary information about the sample.
161  *
162  * Apart from returning the sampled direction, the responsible sampling method
163  * must annotate the record with the associated probability density
164  * and measure.
165  *
166  * \ingroup librender
167  */
169 public:
170  /// Sampled direction
172 
173  /// Probability density at the sample
175 
176  /// Measure associated with the density function
178 
179 public:
180  /// Return a human-readable description of the record
181  std::string toString() const;
182 
183  /**
184  * \brief Create an uninitialized position sampling record
185  *
186  * The resulting data structure is meant to be used
187  * to generate a new direction sample.
188  *
189  * \sa Emitter::sampleDirection
190  */
192 
193  /**
194  * \brief Create a direction sampling record filled with a
195  * specified direction.
196  *
197  * The resulting data structure is meant to be used to
198  * query the density of a direction sampling technique
199  *
200  * \sa Emitter::pdfDirection
201  */
203  EMeasure measure = ESolidAngle)
204  : d(d), measure(measure) { }
205 
206  /**
207  * \brief Create a direction sampling record
208  * from a surface intersection
209  *
210  * This is useful to determine the hypothetical sampling
211  * density of a direction after hitting it using standard
212  * ray tracing. This happens for instance when hitting
213  * the camera aperture in bidirectional rendering
214  * techniques.
215  */
216  inline DirectionSamplingRecord(const Intersection &its,
217  EMeasure measure = ESolidAngle);
218 };
219 
220 /**
221  * \brief Record for solid-angle based area sampling techniques
222  *
223  * This sampling record is used to implement techniques that randomly pick
224  * a position on the surface of an object with the goal of importance sampling
225  * a quantity that is defined over the sphere seen from a given reference point.
226  *
227  * This general approach for sampling positions is named "direct" sampling
228  * throughout Mitsuba motivated by direct illumination rendering techniques,
229  * which represent the most important application.
230  *
231  * This record inherits all fields from \ref PositionSamplingRecord and
232  * extends it with two useful quantities that are cached so that they don't
233  * need to be recomputed many times: the unit direction and length from the
234  * reference position to the sampled point.
235  *
236  * \ingroup librender
237  */
239 public:
240  /// Reference point for direct sampling
242 
243  /**
244  * \brief Optional: normal vector associated with the reference point
245  *
246  * When nonzero, the direct sampling method can use the normal vector
247  * to sample according to the projected solid angle at \c ref.
248  */
250 
251  /// Unit direction from the reference point to the target direction
253 
254  /// Distance from the reference point to the target direction
256 
257 public:
258  /// Create an invalid direct sampling record
259  inline DirectSamplingRecord() { }
260 
261  /**
262  * \brief Create an new direct sampling record for a reference point
263  * \c ref located somewhere in space (i.e. \a not on a surface)
264  *
265  * \param ref
266  * The reference point
267  * \param time
268  * An associated time value
269  */
270  inline DirectSamplingRecord(const Point &ref, Float time)
271  : PositionSamplingRecord(time), ref(ref), refN(0.0f) { }
272 
273  /**
274  * \brief Create an new direct sampling record for a reference point
275  * \c ref located on a surface.
276  *
277  * \param its
278  * The reference point specified using an intersection record
279  */
280  inline DirectSamplingRecord(const Intersection &refIts);
281 
282  /**
283  * \brief Create an new direct sampling record for a reference point
284  * \c ref located in a medium
285  *
286  * \param mRec
287  * The reference point specified using an medium sampling record
288  */
289  inline DirectSamplingRecord(const MediumSamplingRecord &mRec);
290 
291  /**
292  * \brief Create a direct sampling record, which can be used to \a query
293  * the density of a surface position (where there reference point lies on
294  * a \a surface)
295  *
296  * \param ray
297  * Reference to the ray that generated the intersection \c its.
298  * The ray origin must be located at \c refIts.p
299  *
300  * \param its
301  * A surface intersection record (usually on an emitter)
302  */
303 
304  inline void setQuery(
305  const Ray &ray,
306  const Intersection &its,
307  EMeasure measure = ESolidAngle);
308 
309  /// Return a human-readable description of the record
310  std::string toString() const;
311 };
312 
313 /// \cond
314 extern MTS_EXPORT_RENDER std::ostream &operator<<(std::ostream &os, const ETransportMode &mode);
315 extern MTS_EXPORT_RENDER std::ostream &operator<<(std::ostream &os, const EMeasure &measure);
316 /// \endcond
317 
319 
320 #endif /* __MITSUBA_RENDER_COMMON_H_ */
Point p
Sampled position.
Definition: common.h:85
Normal refN
Optional: normal vector associated with the reference point.
Definition: common.h:249
Record for solid-angle based area sampling techniques.
Definition: common.h:238
const ConfigurableObject * object
Optional: Pointer to an associated object.
Definition: common.h:123
Vector d
Unit direction from the reference point to the target direction.
Definition: common.h:252
Three-dimensional normal data structure.
Definition: normal.h:39
DirectSamplingRecord(const Point &ref, Float time)
Create an new direct sampling record for a reference point ref located somewhere in space (i...
Definition: common.h:270
DirectSamplingRecord()
Create an invalid direct sampling record.
Definition: common.h:259
Generic serializable object, which supports construction from a Properties instance.
Definition: cobject.h:40
Generic sampling record for directions.
Definition: common.h:168
Point ref
Reference point for direct sampling.
Definition: common.h:241
DirectionSamplingRecord()
Create an uninitialized position sampling record.
Definition: common.h:191
Float dist
Distance from the reference point to the target direction.
Definition: common.h:255
Normal n
Sampled surface normal (if applicable)
Definition: common.h:91
Generic sampling record for positions.
Definition: common.h:82
Vector d
Sampled direction.
Definition: common.h:171
Discrete measure.
Definition: common.h:66
Length measure.
Definition: common.h:62
Float pdf
Probability density at the sample.
Definition: common.h:94
DirectionSamplingRecord(const Vector &d, EMeasure measure=ESolidAngle)
Create a direction sampling record filled with a specified direction.
Definition: common.h:202
Point2 uv
Optional: 2D sample position associated with the record.
Definition: common.h:113
Invalid measure.
Definition: common.h:58
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
std::ostream & operator<<(std::ostream &out, const DScalar1< Scalar, VecType > &s)
Definition: autodiff.h:392
PositionSamplingRecord()
Create an invalid position sampling record.
Definition: common.h:126
EMeasure measure
Measure associated with the density function.
Definition: common.h:177
Importance transport.
Definition: common.h:40
EMeasure
A list of measures that are associated with various sampling methods in Mitsuba.
Definition: common.h:56
Float time
Associated time value.
Definition: common.h:88
Data record for sampling a point on the in-scattering integral of the RTE.
Definition: medium.h:34
PositionSamplingRecord(Float time)
Create a new position sampling record that can be passed e.g. to Shape::samplePosition.
Definition: common.h:136
std::string toString() const
Return a human-readable description of the record.
Solid angle measure.
Definition: common.h:60
Specifies the number of supported transport modes.
Definition: common.h:42
Definition: fwd.h:99
Reference counting helper.
Definition: ref.h:40
Definition: fwd.h:65
Definition: fwd.h:96
Container for all information related to a surface intersection.
Definition: shape.h:36
Float pdf
Probability density at the sample.
Definition: common.h:174
Definition: fwd.h:100
#define MTS_EXPORT_RENDER
Definition: platform.h:109
Area measure.
Definition: common.h:64
EMeasure measure
Denotes the measure associated with the sample.
Definition: common.h:103
Radiance transport.
Definition: common.h:38
#define MTS_NAMESPACE_END
Definition: platform.h:138
ETransportMode
Specifies the transport mode when sampling or evaluating a scattering function.
Definition: common.h:33