Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vertex.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_BIDIR_VERTEX_H_)
21 #define __MITSUBA_BIDIR_VERTEX_H_
22 
23 #include <mitsuba/bidir/common.h>
24 
26 
27 /**
28  * \brief Bidirectional path vertex data structure
29  *
30  * The path vertex data structure represents a basic interaction within the
31  * path-space light transport framework. It abstracts away the specifics
32  * of the underlying interaction, which simplifies the implementation of
33  * bidirectional rendering techniques such as Bidirectional Path Tracing
34  * or Veach-style Metropolis Light Transport.
35  *
36  * This data structure can describe a several different types of interactions,
37  * including surface and medium scattering events, as well as emission events
38  * by a light source or a sensor (in the bidirectional framework, the response
39  * of a sensor is treated as an emitted quantity)
40  *
41  * A path vertex only describes what happens at the location of a scattering
42  * or emission event -- what happens <em>in between</em> such interactions is
43  * captured in a separate data structure named \ref PathEdge.
44  *
45  * \author Wenzel Jakob
46  * \ingroup libbidir
47  */
49  /* ==================================================================== */
50  //! @{ \name Enumerations and Fields
51  /* ==================================================================== */
52 
53  /// Denotes the size of the auxiliary data section associated with each node
54  enum {
55  EDataSize = MAX(MAX(sizeof(Intersection),
56  sizeof(MediumSamplingRecord)), MAX(
57  sizeof(PositionSamplingRecord), sizeof(EndpointRecord)))
58  };
59 
60  /**
61  * \brief What kind of vertex is this (e.g. medium, surface, emitter)?
62  *
63  * The two special 'supernode' types are used as path endpoints, which greatly
64  * simplifies the control flow of various functions in this data structure and the
65  * MLT/BDPT implementations.
66  */
67  enum EVertexType {
68  /// Invalid/uninitialized vertex
69  EInvalid = 0,
70  /// Special sensor 'supernode' -- just before the sensor sample
71  ESensorSupernode = 1,
72  /// Special emitter 'supernode' -- just before the emitter sample
73  EEmitterSupernode = 2,
74  /// Sampled position on the surface of a sensor
75  ESensorSample = 4,
76  /// Sampled position on the surface of an emitter
77  EEmitterSample = 8,
78  /// Interaction with a scene surface
79  ESurfaceInteraction = 16,
80  /// Interaction with a participating medium
81  EMediumInteraction = 32,
82  /// Union of the two supernode types
83  ESupernode = ESensorSupernode | EEmitterSupernode,
84  /// Union of all other vertex types
85  ENormal = ESensorSample | EEmitterSample
86  | ESurfaceInteraction | EMediumInteraction
87  };
88 
89  /**
90  * \brief Specifies one of several possible path vertex types
91  *
92  * \sa EVertexType
93  */
94  EVertexType type : 7;
95 
96  /**
97  * \brief Denotes whether this vertex \a only supports
98  * sampling from degenerate distributions.
99  *
100  * It's useful to cache this information, since it allows
101  * to quickly determine when certain pairs of vertices
102  * cannot be deterministically connected.
103  *
104  * Examples of degenerate vertices are surface interactions with
105  * dielectric boundaries and certain special cases. For instance, the
106  * sensor supernode can be degenerate when the used sensor does not
107  * cover any area (e.g. because it is a point camera).
108  */
109  bool degenerate : 1;
110 
111  /**
112  * \brief Denotes the measure associated with the
113  * probability densities stored in \ref pdf.
114  *
115  * Certain vertices use sampling methods, whose probability
116  * mass lies on domains that have different associated
117  * measures. An example would be a surface interaction with
118  * a smooth plastic material, where the specular reflection
119  * component is degenerate and the glossy reflection component
120  * is non-degenerate.
121  *
122  * This attribute stores the actual measure (an enumeration
123  * item of type \ref EMeasure) and therefore clarifies whether
124  * or not a degenerate component was sampled. When no sampling
125  * event was generated yet, it is undefined.
126  *
127  * Currently, only three values are permissible:
128  * \ref EArea, \ref EDiscrete, or \ref EInvalidMeasure.
129  *
130  * \sa EMeasure
131  */
132  EMeasure measure : 8;
133 
134  /**
135  * \brief When the current vertex supports sampling
136  * from several components (this currently only applies
137  * to %BSDF lobes), this attribute records the type
138  * sampled component.
139  *
140  * Otherwise, it will be set to zero.
141  */
142  uint16_t componentType;
143 
144  /**
145  * \brief Measurement contribution weight
146  *
147  * This field stores the terms of the path-space measurement contribution
148  * function that are coupled to this specific vertex, divided by the
149  * density of the adjacent vertices in the radiance and importance transport
150  * directions (hence, it is an array with two entries).
151  *
152  * More precisely, it stores
153  * \f[
154  * f(\mathbf{x}_{i-1}\to \mathbf{x}_i\to\mathbf{x}_{i+1})\,
155  * G(\mathbf{x}_i\leftrightarrow\mathbf{x}_{i+1})\,p_A(\mathbf{x}_{i-1}\to
156  * \mathbf{x}_i\to\mathbf{x}_{i+1})^{-1}
157  * \f]
158  *
159  * and
160  *
161  * \f[
162  * f(\mathbf{x}_{i+1}\to \mathbf{x}_i\to\mathbf{x}_{i-1})\,
163  * G(\mathbf{x}_i\leftrightarrow\mathbf{x}_{i-1})\,p_A(\mathbf{x}_{i+1}\to
164  * \mathbf{x}_i\to\mathbf{x}_{i-1})^{-1}
165  * \f]
166  *
167  * Where \f$G\f$ is the geometric term, \f$p_A\f$ is an area density, and
168  * increasing indices are closer to the sensor. Generally much cancellation
169  * will occur in the above expressions. For instance, for a surface
170  * iteractions, this is equal to the BRDF times a cosine foreshortening
171  * factor divided by the solid angle density of the default sampling
172  * method.
173  *
174  * Note that this field does not account for medium-related terms. These
175  * can be found in \ref PathEdge::weight
176  */
178 
179  /**
180  * \brief Area density of the two adjacent vertices
181  *
182  * This field stores the density of the predecessor and sucessor nodes
183  * with respect of the sampling technique implemented by \ref sampleNext().
184  * The measure of this value is specified by the \ref measure field
185  * (generally, it is the density per unit area).
186  *
187  * When one of the adjacent vertices is a medium interaction (i.e. it is
188  * not located on a surface), the stored probability will specify the density
189  * on a hypothetical surface oriented perpendicularly to the transport
190  * direction.
191  *
192  * Note that this field does not account for medium-related terms. When
193  * an adjacent vertex is a medium interaction, its volume density can be
194  * recovered by computing the product of \c pdf and \ref PathEdge::pdf
195  * of the associated transport edge.
196  */
198 
199  /// \brief Termination weight due to russian roulette (used by BDPT)
201 
202  /**
203  * \brief Auxilary node-depependent data associated with each vertex
204  *
205  * This "payload" field is large enough to describe any possible kind of
206  * vertex. Currently, it is cast to the desired type of data structure
207  * which wreaks havoc with strict aliasing (and hence it is disabled
208  * for all bidirectional code).
209  *
210  * Once C++11 is widely supported across all target platforms, this
211  * should be replaced by an unrestricted union.
212  */
213  uint8_t data[EDataSize];
214 
215  //! @}
216  /* ==================================================================== */
217 
218  /* ==================================================================== */
219  //! @{ \name Sampling-related functions
220  /* ==================================================================== */
221 
222  /**
223  * \brief Generate a path endpoint that can be used to start
224  * a random walk
225  *
226  * \param scene
227  * Pointer to the underlying scene
228  * \param mode
229  * Specifies the desired mode of transport, i.e. radiance or
230  * importance transport
231  * \param time
232  * Denotes the time value that will be associated with this
233  * endpoint and any paths generated starting from there.
234  */
235  void makeEndpoint(const Scene *scene, Float time, ETransportMode mode);
236 
237  /**
238  * \brief Sample the next vertex in a random walk using the default
239  * sampling technique implemented by the current vertex.
240  *
241  * Given a vertex, its predecessor, as well as the edge in between them,
242  * this function samples a new successor edge and vertex.
243  *
244  * \param scene
245  * Pointer to the underlying scene
246  * \param sampler
247  * Pointer to a sample generator
248  * \param pred
249  * Pointer to the preceding vertex (if any) and \c NULL otherwise
250  * \param predEdge
251  * Edge to the preceding edge (if any) and \c NULL otherwise
252  * \param succEdge
253  * Pointer to an unused edge data structure, which will be filled
254  * with information about the edge between the current vertex and
255  * the newly sampled successor.
256  * \param succ
257  * Pointer to an unused vertex data structure, which will be filled
258  * with information about the successor vertex
259  * \param mode
260  * Specifies whether radiance or importance is being transported
261  * \param russianRoulette
262  * Should russian roulette be used while sampling the successor?
263  * Note that the effects of this are only captured in the \c rrWeight
264  * field -- the \ref weight and \ref pdf fields intentionally remain unchanged.
265  * \param throughput
266  * If russian roulette is active, this parameter should point to a
267  * spectrum value that is used to record the aggregate path weight
268  * thus far. It will be updated automatically to account for the current
269  * interaction.
270  * \return \c true on success
271  */
272  bool sampleNext(const Scene *scene, Sampler *sampler,
273  const PathVertex *pred, const PathEdge *predEdge,
274  PathEdge *succEdge, PathVertex *succ,
275  ETransportMode mode, bool russianRoulette = false,
276  Spectrum *throughput = NULL);
277 
278  /**
279  * \brief \a Direct sampling: given the current vertex as a reference
280  * sample an emitter (or sensor) position that has a nonzero emission
281  * (or response) towards it.
282  *
283  * This can be seen as a generalization of direct illumination sampling
284  * that can be used for both emitter and sensor endpoints.
285  *
286  * Ideally, the implementation should importance sample the product of
287  * the emission or response profile and the geometry term between the
288  * reference point and the sampled position. In practice, one of these
289  * usually has to be sacrificed.
290  *
291  * \param scene
292  * Pointer to the underlying scene
293  * \param sampler
294  * Pointer to a sample generator
295  * \param endpoint
296  * Unused vertex data structure, which will be configured as
297  * the endpoint associated with \c sample.
298  * \param edge
299  * Unused edge data structure, which will be configured
300  * as the edge between \c endpoint and \c sample.
301  * \param sample
302  * Unused vertex data structure, which will hold the
303  * sampled sensor or emitter position
304  * \param mode
305  * Specifies whether radiance or importance is being transported
306  * \return The emitted radiance or importance divided by the
307  * sample probability per unit area per unit solid angle.
308  */
309  Spectrum sampleDirect(const Scene *scene, Sampler *sampler,
310  PathVertex *endpoint, PathEdge *edge, PathVertex *sample,
311  ETransportMode mode) const;
312 
313  /**
314  * \brief Sample the first vertices on a sensor subpath such that
315  * they contribute to a specified pixel in the output image
316  *
317  * This function samples the spatial and directional components of the sensor
318  * and is similar to calling \ref sampleNext() two times in sequence starting
319  * from a sensor supernode. The main difference is that the resulting subpath
320  * passes through a specified pixel position, which is important to implement
321  * algorithms that parallelize rendering of images by processing it in separate
322  * blocks. If this function is called once for every pixel in the output
323  * image, the resulting path distribution is identical to what would have
324  * been obtained via \ref sampleNext().
325  *
326  * The function throws an exception when the current vertex is not
327  * a sensor supernode.
328  *
329  * \param scene
330  * Pointer to the underlying scene
331  * \param sampler
332  * Pointer to a sample generator
333  * \param pixelPosition
334  * Specifies the desired pixel position
335  * \param e0
336  * Pointer to the first edge on the sensor subpath
337  * \param e0
338  * Pointer to the first edge on the sensor subpath
339  * \param v1
340  * Pointer to the second vertex on the sensor subpath
341  * \param v2
342  * Pointer to the third vertex on the sensor subpath
343  * \return The number of successful sampling operations (i.e.
344  * \c 0 if sensor sampling failed, \c 1 if no surface/medium
345  * interaction was encountered, or \c 2 if all data structures
346  * were successfully filled)
347  */
348  int sampleSensor(const Scene *scene, Sampler *sampler, const Point2i &pixelPosition,
349  PathEdge *e0, PathVertex *v1, PathEdge *e1, PathVertex *v2);
350 
351  /**
352  * \brief Create a perturbed successor vertex and edge
353  *
354  * This function behaves similar to \ref sampleNext() in that it
355  * generates a successor edge and vertex.
356  *
357  * The main difference is that the desired direction, distance, and
358  * type of the successor vertex are all specified, which makes the
359  * sampling process completely deterministic. This is useful for
360  * implementing path-space perturbation strategies.
361  *
362  * This function only applies to non-supernode vertices.
363  *
364  * \param scene
365  * Pointer to the underlying scene
366  * \param pred
367  * Pointer to the preceding vertex (if any) and \c NULL otherwise
368  * \param predEdge
369  * Edge to the preceding edge (if any) and \c NULL otherwise
370  * \param succEdge
371  * Pointer to an unused edge data structure, which will be filled
372  * with information about the edge between the current vertex and
373  * the new successor.
374  * \param succ
375  * Pointer to an unused vertex data structure, which will be filled
376  * with information about the successor vertex
377  * \param d
378  * Specifies the desired outgoing direction at the current vertex
379  * \param dist
380  * Specifies the desired distance between the current vertex and \c succ
381  * (this only applies when <tt>desiredType=EMediumInteraction</tt>)
382  * \param desiredType
383  * Specifies the desired vertex type of \c succ.
384  * \param mode
385  * Specifies whether radiance or importance is being transported
386  * \return \c true on success
387  */
388  bool perturbDirection(const Scene *scene, const PathVertex *pred,
389  const PathEdge *predEdge, PathEdge *succEdge, PathVertex *succ,
390  const Vector &d, Float dist, EVertexType desiredType, ETransportMode mode);
391 
392  /**
393  *
394  */
395  bool perturbPosition(const Scene *scene, Sampler *sampler, Float stddev);
396  Float perturbPositionPdf(const PathVertex *target, Float stddev) const;
397 
398  /**
399  * \brief Propagate a perturbation through an ideally specular interaction
400  *
401  * This function behaves similar to \ref sampleNext() and \ref
402  * perturbDirection() in that it generates a successor edge and vertex.
403  *
404  * The main difference is that it only works for specular interactions,
405  * where the requested type of interaction (reflection/refraction) is
406  * additionally specified, which makese the sampling process completely
407  * deterministic. This is useful for implementing path-space
408  * perturbation strategies. For now, it is only used by the perturbations
409  * of Veach and Guibas.
410  *
411  * This function only applies to surface interaction vertices.
412  *
413  * \param scene
414  * Pointer to the underlying scene
415  * \param pred
416  * Pointer to the preceding vertex (if any) and \c NULL otherwise
417  * \param predEdge
418  * Edge to the preceding edge (if any) and \c NULL otherwise
419  * \param succEdge
420  * Pointer to an unused edge data structure, which will be filled
421  * with information about the edge between the current vertex and
422  * the new successor.
423  * \param dist
424  * Specifies the desired distance between the current vertex and \c succ
425  * (this only applies when <tt>desiredType=EMediumInteraction</tt>)
426  * \param desiredType
427  * Specifies the desired vertex type of \c succ.
428  * \param componentType
429  * Specifies the desired type of scattering interaction (equivalent
430  * to \ref BSDF::typeMask)
431  * \param succ
432  * Pointer to an unused vertex data structure, which will be filled
433  * with information about the successor vertex
434  * \param dist
435  * Specifies the desired distance between the current vertex and
436  * \c succ (this only applies to medium interactions)
437  * \param mode
438  * Specifies whether radiance or importance is being transported
439  * \return \c true on success
440  */
441  bool propagatePerturbation(const Scene *scene, const PathVertex *pred,
442  const PathEdge *predEdge, PathEdge *succEdge, PathVertex *succ,
443  unsigned int componentType, Float dist, EVertexType desiredType,
444  ETransportMode mode);
445 
446  //! @}
447  /* ==================================================================== */
448 
449  /* ==================================================================== */
450  //! @{ \name Query functions
451  /* ==================================================================== */
452 
453  /**
454  * \brief Evaluate the terms of the measurement contribution function
455  * that are associated with this vertex.
456  *
457  * Compute a single term of the contribution weighting function associated
458  * with the current node given a predecessor and successor node.
459  *
460  * Note: this function only accounts for the factor associated with this
461  * specific vertex -- to account for an adjacent edge, refer to
462  * \ref PathEdge::eval.
463  *
464  * \param scene
465  * Pointer to the underlying scene
466  * \param pred
467  * Pointer to the preceding vertex (if any) and \c NULL otherwise
468  * \param succ
469  * Pointer to the successor vertex (if any) and \c NULL otherwise
470  * \param mode
471  * Specifies whether radiance or importance is being transported
472  * \param measure
473  * Specifies the measure of the queried component. This is necessary
474  * to handle mixture scattering functions, whose components are
475  * defined on spaces with different measures.
476  * \return The contribution weighting factor
477  */
478  Spectrum eval(const Scene *scene, const PathVertex *pred,
479  const PathVertex *succ, ETransportMode mode, EMeasure measure = EArea) const;
480 
481  /**
482  * \brief Compute the density of a successor node
483  *
484  * This function computes the hypothetical scattering-related sampling density
485  * of a given successor node when using the sampling technique implemented by
486  * \ref sampleNext(). Since this technique conditions on a predecessor vertex,
487  * it must also be provided here. The desired measure (e.g. area/solid angle/discrete)
488  * can be provided as an extra parameter.
489  *
490  * Note: this function only computes probability associated with the
491  * vertices -- to account for edges, refer to \ref PathEdge::evalPdf.
492  *
493  * \param scene
494  * Pointer to the underlying scene
495  * \param pred
496  * Pointer to the preceding vertex (if any) and \c NULL otherwise
497  * \param succ
498  * Pointer to the successor vertex (if any) and \c NULL otherwise
499  * \param mode
500  * Specifies whether radiance or importance is being transported
501  * \param measure
502  * Specifies the measure of the queried component. This is necessary
503  * to handle mixture scattering functions, whose components are
504  * defined on spaces with different measures.
505  * \return The computed probability density
506  */
507  Float evalPdf(const Scene *scene, const PathVertex *pred,
508  const PathVertex *succ, ETransportMode mode, EMeasure measure = EArea) const;
509 
510  /**
511  * \brief Compute the area density of a provided emitter or sensor
512  * sample with respect the \a direct sampling technique implemented in
513  * \ref sampleDirect().
514  *
515  * The current vertex is taken to be the reference point of the direct
516  * sampling technique.
517  *
518  * \param scene
519  * Pointer to the underlying scene
520  * \param mode
521  * Specifies whether radiance or importance is being transported
522  * \param sample
523  * An emitter or sensor sample
524  * \param measure
525  * Specifies the measure of the queried component. This is necessary
526  * to handle scattering functions, whose components are
527  * defined on spaces with different measures.
528  * \return The density of \c sample conditioned on this vertex.
529  */
530  Float evalPdfDirect(const Scene *scene, const PathVertex *sample,
531  ETransportMode mode, EMeasure measure = EArea) const;
532 
533  /**
534  * \brief Determine the medium that fills the space between
535  * the current vertex and a specified successor
536  *
537  * This function assumes that there is no surface between \c this
538  * and \c succ, hence it does not account for intermediate medium
539  * changes.
540  *
541  * \param predEdge
542  * Pointer to an edge that connects the current node to its predecessor
543  * \param succ
544  * Pointer to the successor vertex in question
545  * \return
546  * The medium between \c this and \c succ
547  */
548  const Medium *getTargetMedium(const PathEdge *predEdge,
549  const PathVertex *succ) const;
550 
551  /**
552  * \brief Determine the medium that fills the space in direction \c d
553  *
554  * \param predEdge
555  * Pointer to an edge that connects the current node to its predecessor
556  * \param d
557  * A world-space direction
558  * \return
559  * The medium containing the ray <tt>(this->getPosition(), d)</tt>
560  */
561  const Medium *getTargetMedium(const PathEdge *predEdge,
562  const Vector &d) const;
563 
564  //! @}
565  /* ==================================================================== */
566 
567  /* ==================================================================== */
568  //! @{ \name Accessors
569  /* ==================================================================== */
570 
571  /// Return the type associated with this vertex
572  inline EVertexType getType() const { return (EVertexType) type; }
573 
574  /**
575  * \brief Return the position associated with this vertex
576  *
577  * Throws an exception when called on a supernode
578  */
579  Point getPosition() const;
580 
581  /// Check if the vertex lies on a surface
582  inline bool isOnSurface() const {
583  return (type == ESurfaceInteraction) || ((type == EEmitterSample ||
584  type == ESensorSample) && static_cast<const AbstractEmitter *>(
585  getPositionSamplingRecord().object)->getType() & AbstractEmitter::EOnSurface);
586  }
587 
588  /**
589  * \brief Returns whether or not this vertex describes a "null" scattering interaction.
590  *
591  * A null interaction is a degenerate scattering event with a Dirac delta peak in the
592  * forward direction. Apart from a potential influence on their weight, particles
593  * will pass through such an interface unchanged.
594  */
595  inline bool isNullInteraction() const {
596  return type == ESurfaceInteraction && componentType == BSDF::ENull;
597  }
598 
599  /**
600  * \brief Returns whether or not this vertex describes a diffuse surface
601  * scattering interaction.
602  */
603  inline bool isDiffuseInteraction() const {
604  return type == ESurfaceInteraction &&
605  (componentType == BSDF::EDiffuseReflection || componentType == BSDF::EDiffuseTransmission);
606  }
607 
608  /**
609  * \brief Returns whether or not this vertex describes a 100% absorbing surface
610  *
611  * Such is the case on emitters/sensors that don't have an explicit BSDF assigned
612  * to them. It is useful to be able to query this to avoid some useless connection
613  * attempts involving these vertices.
614  */
615  inline bool isAbsorbing() const {
616  return (type == ESurfaceInteraction &&
617  (getIntersection().shape->getBSDF()->getType() & BSDF::EAll) == 0);
618  }
619 
620  /**
621  * \brief Return the component type associated with this vertex
622  *
623  * This currently only applies to surface interactions. The returned
624  * result will consist of flags in \ref BSDF::EBSDFType.
625  */
626  inline unsigned int getComponentType() const { return (unsigned int) componentType; }
627 
628  /**
629  * \brief Return the geometric surface normal associated with this vertex
630  *
631  * Throws an exception when called on a supernode or a medium interaction
632  */
633  Normal getGeometricNormal() const;
634 
635  /**
636  * \brief Return the shading surface normal associated with this vertex
637  *
638  * Throws an exception when called on a supernode or a medium interaction
639  */
640  Normal getShadingNormal() const;
641 
642  /// Return the time value associated with this node
643  Float getTime() const;
644 
645  /// Is this vertex a supernode?
646  inline bool isSupernode() const { return type & ESupernode; }
647  /// Is this vertex a sensor super-node?
648  inline bool isSensorSupernode() const { return type == ESensorSupernode; }
649  /// Is this vertex a emitter super-node?
650  inline bool isEmitterSupernode() const { return type == EEmitterSupernode; }
651  /// Is this vertex an emitter sample?
652  inline bool isEmitterSample() const { return type == EEmitterSample; }
653  /// Is this vertex a lens sample?
654  inline bool isSensorSample() const { return type == ESensorSample; }
655  /// Is this vertex a surface interaction?
656  inline bool isSurfaceInteraction() const { return type == ESurfaceInteraction; }
657  /// Is this vertex a medium interaction?
658  inline bool isMediumInteraction() const { return type == EMediumInteraction; }
659 
660  /// Return the endpoint record associated with this node
663  reinterpret_cast<EndpointRecord*>(&data[0]);
664  return *ptr;
665  }
666 
667  /// Return the endpoint record associated with this node (const)
668  inline const EndpointRecord &getEndpointRecord() const {
669  const EndpointRecord* ptr MTS_MAY_ALIAS =
670  reinterpret_cast<const EndpointRecord*>(&data[0]);
671  return *ptr;
672  }
673 
674  /// Return the position sampling record associated with this node
677  reinterpret_cast<PositionSamplingRecord*>(&data[0]);
678  return *ptr;
679  }
680 
681  /// Return the position sampling record associated with this node (const)
684  reinterpret_cast<const PositionSamplingRecord*>(&data[0]);
685  return *ptr;
686  }
687 
688  /// Return the intersection record associated with this node
691  reinterpret_cast<Intersection*>(&data[0]);
692  return *ptr;
693  }
694 
695  /// Return the intersection record associated with this node (const)
696  inline const Intersection &getIntersection() const {
697  const Intersection* ptr MTS_MAY_ALIAS =
698  reinterpret_cast<const Intersection*>(&data[0]);
699  return *ptr;
700  }
701 
702  /// Return the medium sampling record associated with this node
705  reinterpret_cast<MediumSamplingRecord*>(&data[0]);
706  return *ptr;
707  }
708 
709  /// Return the medium sampling record associated with this node
712  reinterpret_cast<const MediumSamplingRecord*>(&data[0]);
713  return *ptr;
714  }
715 
716  /// Return the fractional pixel position associated with a sensor sample
717  inline const Point2 &getSamplePosition() const {
718  return getPositionSamplingRecord().uv;
719  }
720 
721  /// Return the abstract emitter associated with a sensor/emitter sample
722  inline const AbstractEmitter *getAbstractEmitter() const {
723  return static_cast<const AbstractEmitter *>(
724  getPositionSamplingRecord().object);
725  }
726 
727  /**
728  * \brief Returns whether or not this vertex is degenerate, i.e.
729  * its distribution has measure zero
730  */
731  inline bool isDegenerate() const { return degenerate; }
732 
733  /**
734  * \brief Returns whether or not this vertex can be deterministically
735  * connected to other vertices.
736  *
737  * This is the case when <tt>\ref degenerate == false</tt> and
738  * <tt>\ref measure != EDiscrete</tt>.
739  */
740  inline bool isConnectable() const { return !degenerate && measure != EDiscrete; }
741 
742  /**
743  * \brief Special routine for sensor sample vertices: given a successor
744  * \c succ, update the fractional pixel position stored in the vertex.
745  *
746  * \param v
747  * Pointer to the target vertex
748  *
749  * \return \c true upon success (i.e. when the point is in the
750  * sensor's field of view)
751  */
752  bool updateSamplePosition(const PathVertex *succ);
753 
754  /**
755  * \brief Special routine for sensor sample vertices: given a successor
756  * \c succ, return its associated fractional pixel position.
757  *
758  * \param v
759  * Pointer to the target vertex
760  *
761  * \param result
762  * Reference to a 2D point that will be set to the fractional
763  * pixel coordinates associated with \c succ.
764  *
765  * \return \c true upon success (i.e. when the point is in the
766  * sensor's field of view)
767  */
768  bool getSamplePosition(const PathVertex *succ, Point2 &result) const;
769 
770  //! @}
771  /* ==================================================================== */
772 
773  /* ==================================================================== */
774  //! @{ \name Miscellaneous
775  /* ==================================================================== */
776 
777  /**
778  * \brief Cast this vertex into an equivalent from having a different type
779  *
780  * Sometimes it is necessary to cast a vertex into a different type.
781  * An example when this occurs is when a surface interaction vertex
782  * lies on the surface of an emitter or a sensor. In such a situation,
783  * it may be useful to retroactively turn it into an emitter or sensor
784  * sample vertex located at the same position. This function allows
785  * to do precisely that.
786  *
787  * \param scene
788  * A pointer to the underlying scene
789  * \param desired
790  * Desired type after the cast
791  * \return \c true on success. When returning \c false, the
792  * function did not make any changes.
793  */
794  bool cast(const Scene *scene, EVertexType desired);
795 
796  /**
797  * \brief Verify the cached values stored in this path vertex
798  * for consistency
799  *
800  * This function re-evaluates a series of quantities associated with
801  * this vertex and compares them to locally cached values including
802  * \ref pdf, \ref value, and \ref degenerate. If any mismatch
803  * is found, the function sends debug output to a specified output
804  * stream and returns \c false.
805  *
806  * \param scene
807  * Pointer to the underlying scene
808  * \param pred
809  * Pointer to the preceding vertex (if any) and \c NULL otherwise
810  * \param succ
811  * Pointer to the successor vertex (if any) and \c NULL otherwise
812  * \param mode
813  * Transport mode -- disambiguates the meaning of \c pred and \c succ.
814  * \param os
815  * Target output stream for error messages
816  */
817  bool verify(const Scene *scene, const PathVertex *adjL,
818  const PathVertex *adjE, ETransportMode mode, std::ostream &os) const;
819 
820  /**
821  * \brief Given the specified predecessor and successor, update
822  * the cached values stored in this vertex
823  *
824  * \param pred
825  * Pointer to the predecessor vertex (if any) and \c NULL otherwise
826  * \param succ
827  * Pointer to the successor vertex (if any) and \c NULL otherwise
828  * \param mode
829  * Specifies the direction of light transport
830  * \return \c false when there is no throughput
831  */
832  bool update(const Scene *scene, const PathVertex *pred,
833  const PathVertex *succ, ETransportMode mode, EMeasure measure = EArea);
834 
835  /**
836  * \brief Create a connection between two disconnected subpaths
837  *
838  * This function can be used to connect two seperately created emitter
839  * and sensor subpaths so that they can be merged into a \ref Path data
840  * structure. The function checks that the vertices \c vs and \c vt are
841  * mutually visible, and that there is a nonzero throughput between them.
842  * If that is the case, it updates the cached values stored in \c vs,
843  * \c edge, and \c vt.
844  *
845  * The expected order of the parameters in path-space is
846  * <pre>
847  * (pred) -> predEdge -> (vs) -> edge -> (vt) -> succEdge -> (succ)
848  * </pre>
849  * where entries in parentheses denote vertices,
850  * \c pred is the closer to the light source, and \c succ
851  * is the closer to the sensor.
852  *
853  * \param scene
854  * Pointer to the underlying scene
855  * \param pred
856  * Pointer to the predecessor vertex of \c vs (towards the emitter)
857  * \param predEdge
858  * Pointer to an edge between \c pred and \c vs.
859  * \param vs
860  * Last vertex of the emitter subpath to be connected. The
861  * cached values of this vertex will be updated should the
862  * connection attempt succeed.
863  * \param edge
864  * Pointer to an unused edge data structure, which will be
865  * annotated with information about the medium-related transport
866  * between \c vs and \c vt.
867  * \param vt
868  * Last vertex of the sensor subpath to be connected. The
869  * cached values of this vertex will be updated should the
870  * connection attempt succeed.
871  * \param succEdge
872  * Pointer to an edge between \c vt and \c succ.
873  * \param succ
874  * Pointer to the successor vertex of \c vt (towards the sensor)
875  * \return \c true upon success, \c false when there is no
876  * throughput or an inconsistency has been detected.
877  */
878  static bool connect(const Scene *scene,
879  const PathVertex *pred, const PathEdge *predEdge,
880  PathVertex *vs, PathEdge *edge, PathVertex *vt,
881  const PathEdge *succEdge, const PathVertex *succ);
882 
883  /// Like the above, but can be used to connect delta endpoints
884  static bool connect(const Scene *scene,
885  const PathVertex *pred, const PathEdge *predEdge,
886  PathVertex *vs, PathEdge *edge, PathVertex *vt,
887  const PathEdge *succEdge, const PathVertex *succ,
888  EMeasure vsMeasure, EMeasure vtMeasure);
889 
890  /// Create a deep copy of this vertex
891  PathVertex *clone(MemoryPool &pool) const;
892 
893  /// Return a string representation of the information stored in this vertex
894  std::string toString() const;
895 
896  /// Compare this vertex against another vertex
897  bool operator==(const PathVertex &vertex) const;
898 
899  /// Compare this vertex against another vertex
900  inline bool operator!=(const PathVertex &vertex) const {
901  return !operator==(vertex);
902  }
903 
904  //! @}
905  /* ==================================================================== */
906 };
907 
908 /// \cond
909 extern MTS_EXPORT_BIDIR
910  std::ostream &operator<<(std::ostream &os, PathVertex::EVertexType type);
911 /// \endcond
912 
914 
915 #endif /* __MITSUBA_BIDIR_VERTEX_H_ */
#define MAX(a, b)
Definition: common.h:36
Abstract participating medium.
Definition: medium.h:103
#define MTS_EXPORT_BIDIR
Definition: platform.h:119
Three-dimensional normal data structure.
Definition: normal.h:39
Bidirectional path vertex data structure.
Definition: vertex.h:48
const MediumSamplingRecord & getMediumSamplingRecord() const
Return the medium sampling record associated with this node.
Definition: vertex.h:710
bool isMediumInteraction() const
Is this vertex a medium interaction?
Definition: vertex.h:658
unsigned int getComponentType() const
Return the component type associated with this vertex.
Definition: vertex.h:626
bool isDegenerate() const
Returns whether or not this vertex is degenerate, i.e. its distribution has measure zero...
Definition: vertex.h:731
Abstract radiance/importance emitter interface.
Definition: emitter.h:70
EVertexType
What kind of vertex is this (e.g. medium, surface, emitter)?
Definition: vertex.h:67
bool isEmitterSample() const
Is this vertex an emitter sample?
Definition: vertex.h:652
Generic sampling record for positions.
Definition: common.h:82
bool isEmitterSupernode() const
Is this vertex a emitter super-node?
Definition: vertex.h:650
Principal scene data structure.
Definition: scene.h:49
Discrete measure.
Definition: common.h:66
const EndpointRecord & getEndpointRecord() const
Return the endpoint record associated with this node (const)
Definition: vertex.h:668
Base class of all sample generators.
Definition: sampler.h:66
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
std::ostream & operator<<(std::ostream &out, const DScalar1< Scalar, VecType > &s)
Definition: autodiff.h:392
EndpointRecord & getEndpointRecord()
Return the endpoint record associated with this node.
Definition: vertex.h:661
MediumSamplingRecord & getMediumSamplingRecord()
Return the medium sampling record associated with this node.
Definition: vertex.h:703
PositionSamplingRecord & getPositionSamplingRecord()
Return the position sampling record associated with this node.
Definition: vertex.h:675
#define MTS_MAY_ALIAS
Definition: platform.h:88
EMeasure
A list of measures that are associated with various sampling methods in Mitsuba.
Definition: common.h:56
Float rrWeight
Termination weight due to russian roulette (used by BDPT)
Definition: vertex.h:200
bool isSensorSupernode() const
Is this vertex a sensor super-node?
Definition: vertex.h:648
bool isDiffuseInteraction() const
Returns whether or not this vertex describes a diffuse surface scattering interaction.
Definition: vertex.h:603
Data record for sampling a point on the in-scattering integral of the RTE.
Definition: medium.h:34
bool isSensorSample() const
Is this vertex a lens sample?
Definition: vertex.h:654
Specifies the number of supported transport modes.
Definition: common.h:42
Definition: fwd.h:99
EVertexType getType() const
Return the type associated with this vertex.
Definition: vertex.h:572
Intersection & getIntersection()
Return the intersection record associated with this node.
Definition: vertex.h:689
Bidirectional path edge data structure.
Definition: edge.h:46
bool isOnSurface() const
Check if the vertex lies on a surface.
Definition: vertex.h:582
const Intersection & getIntersection() const
Return the intersection record associated with this node (const)
Definition: vertex.h:696
Definition: fwd.h:96
const Point2 & getSamplePosition() const
Return the fractional pixel position associated with a sensor sample.
Definition: vertex.h:717
bool isConnectable() const
Returns whether or not this vertex can be deterministically connected to other vertices.
Definition: vertex.h:740
bool isSurfaceInteraction() const
Is this vertex a surface interaction?
Definition: vertex.h:656
Container for all information related to a surface intersection.
Definition: shape.h:36
Definition: fwd.h:100
Data record associated with path endpoints (aka supernodes) in the path-space framework.
Definition: common.h:48
Discrete spectral power distribution based on a number of wavelength bins over the 360-830 nm range...
Definition: spectrum.h:663
bool isSupernode() const
Is this vertex a supernode?
Definition: vertex.h:646
Area measure.
Definition: common.h:64
bool operator!=(const PathVertex &vertex) const
Compare this vertex against another vertex.
Definition: vertex.h:900
Definition: mempool.h:29
bool isAbsorbing() const
Returns whether or not this vertex describes a 100% absorbing surface.
Definition: vertex.h:615
const PositionSamplingRecord & getPositionSamplingRecord() const
Return the position sampling record associated with this node (const)
Definition: vertex.h:682
#define MTS_NAMESPACE_END
Definition: platform.h:138
ETransportMode
Specifies the transport mode when sampling or evaluating a scattering function.
Definition: common.h:33
const AbstractEmitter * getAbstractEmitter() const
Return the abstract emitter associated with a sensor/emitter sample.
Definition: vertex.h:722
uint16_t componentType
When the current vertex supports sampling from several components (this currently only applies to BSD...
Definition: vertex.h:142
bool isNullInteraction() const
Returns whether or not this vertex describes a &quot;null&quot; scattering interaction.
Definition: vertex.h:595