Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mutator.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_MUTATOR_H_)
21 #define __MITSUBA_BIDIR_MUTATOR_H_
22 
23 #include <mitsuba/bidir/path.h>
24 
26 
27 /**
28  * \brief Generic interface to path-space mutators
29  *
30  * This is the superclass of all path-space mutators, such as
31  * the bidirectional mutation or lens perturbation in Veach-MLT.
32  */
34 public:
35  /// Specifies the type of mutation implemented by the mutator
37  EBidirectionalMutation = 0,
44  EMutationTypeCount
45  };
46 
47  /// What kind of mutations does this mutator perform?
48  virtual EMutationType getType() const = 0;
49 
50  /// Determine the general "suitability" of this mutator for a given kind of path
51  virtual Float suitability(const Path &path) const = 0;
52 
53  /**
54  * \brief Given a path, this function produces a new proposal
55  * according to the internally implemented mutation strategy
56  *
57  * \param source
58  * The sampling strategy implemented by the mutator
59  * will condition on this path.
60  *
61  * \param proposal
62  * Path data structure to be filled with the proposed mutated path
63  *
64  * \param muRec
65  * Data record that describes the sampled mutation strategy
66  *
67  * \param sourceMuRec
68  * Data record that describes the last successful mutation strategy
69  * (for the source path)
70  *
71  * \return \a true upon success. When the sampling step is
72  * unsuccessful (this could happen due to various
73  * reasons), the function returns <tt>false</tt>.
74 
75  */
76  virtual bool sampleMutation(Path &source, Path &proposal,
77  MutationRecord &muRec, const MutationRecord& sourceMuRec) = 0;
78 
79  /**
80  * \brief For a pair of paths, this function computes the inverse
81  * transition probability (matching the Q term in [Veach 97])
82  *
83  * \param source
84  * A path data structure containing the original path
85  *
86  * \param proposal
87  * A path data structure containing the proposed mutated path
88  *
89  * \param muRec
90  * Data record that describes the mutation strategy, which
91  * transformed \c source to \c proposal.
92  */
93  virtual Float Q(const Path &source, const Path &proposal,
94  const MutationRecord &muRec) const = 0;
95 
96  /**
97  * \brief Record an accepted mutation
98  *
99  * This function exists to allow mutators to track their
100  * acceptance rate and other statistics.
101  */
102  virtual void accept(const MutationRecord &muRec) = 0;
103 
105 protected:
106  /// Virtual destructor
107  virtual ~Mutator() { }
108 };
109 
110 /**
111  * \brief Stores supplemental information about an executed mutation strategy
112  *
113  * These records are filled in by \ref Mutator::sampleMutation().
114  */
116  Mutator::EMutationType type; ///< Type of executed mutation
117  int l; ///< Left vertex of the affected range
118  int m; ///< Right vertex of the affected range
119  int ka; ///< Size of the insertion
120  Spectrum weight; ///< Spectral weight of the unchanged portion
121  int extra[5];
122 
123  inline MutationRecord() { }
125  int m, int ka, const Spectrum &weight)
126  : type(type), l(l), m(m), ka(ka), weight(weight) { }
127 
129  MutationRecord result(type, l, l+ka, m-l, weight);
130  memcpy(result.extra, extra, sizeof(extra));
131  return result;
132  }
133 
134  std::string toString() const;
135 };
136 
137 extern MTS_EXPORT_BIDIR std::ostream &operator<<(
138  std::ostream &os, const Mutator::EMutationType &type);
139 
140 /**
141  * \brief Medium-aware mutator base class
142  */
144 public:
146 protected:
147  /// Protected constructor
148  MutatorBase();
149 
150  /// Virtual destructor
151  virtual ~MutatorBase() { }
152 
153  /// Perturb a distance within a medium
154  Float perturbMediumDistance(Sampler *sampler,
155  const PathVertex *vertex);
156 
157  /// Density function of \ref perturbMediumDistance
158  Float pdfMediumPerturbation(const PathVertex *oldVertex,
159  const PathEdge *oldEdge, const PathEdge *newEdge) const;
160 
161 protected:
163 };
164 
166 
167 #endif /* __MITSUBA_BIDIR_MUTATOR_H_ */
std::ostream & operator<<(std::ostream &os, const Mutator::EMutationType &type)
int ka
Size of the insertion.
Definition: mutator.h:119
#define MTS_EXPORT_BIDIR
Definition: platform.h:119
int extra[5]
Definition: mutator.h:121
Medium-aware mutator base class.
Definition: mutator.h:143
Bidirectional path vertex data structure.
Definition: vertex.h:48
int m
Right vertex of the affected range.
Definition: mutator.h:118
Stores supplemental information about an executed mutation strategy.
Definition: mutator.h:115
Float m_mediumDensityMultiplier
Definition: mutator.h:162
Generic interface to path-space mutators.
Definition: mutator.h:33
MutationRecord(Mutator::EMutationType type, int l, int m, int ka, const Spectrum &weight)
Definition: mutator.h:124
Mutator::EMutationType type
Type of executed mutation.
Definition: mutator.h:116
Base class of all sample generators.
Definition: sampler.h:66
Bidirectional path data structure.
Definition: path.h:46
MutationRecord reverse() const
Definition: mutator.h:128
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Spectrum weight
Spectral weight of the unchanged portion.
Definition: mutator.h:120
Definition: mutator.h:38
EMutationType
Specifies the type of mutation implemented by the mutator.
Definition: mutator.h:36
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Bidirectional path edge data structure.
Definition: edge.h:46
MutationRecord()
Definition: mutator.h:123
Parent of all Mitsuba classes.
Definition: object.h:38
int l
Left vertex of the affected range.
Definition: mutator.h:117
Discrete spectral power distribution based on a number of wavelength bins over the 360-830 nm range...
Definition: spectrum.h:663
#define MTS_NAMESPACE_END
Definition: platform.h:138