Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
particleproc.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_PARTICLEPROC_H_)
21 #define __MITSUBA_RENDER_PARTICLEPROC_H_
22 
23 #include <mitsuba/render/scene.h>
24 
26 
27 /**
28  * \brief Abstract parallel particle tracing process
29  *
30  * This class implements a particle tracer similar to what is
31  * described in appendix 4.A of Eric Veach's PhD thesis. Particles
32  * are emitted from the light source and subsequently perform a random
33  * walk that includes both surface and medium scattering events. The
34  * work is spread out over multiple cores/machines. For every such
35  * event,a custom routine is invoked.
36  *
37  * To actually use this class, you must extend it and implement the
38  * function \ref createWorkProcessor(), which should return a subclass
39  * of \ref ParticleTracer with overridden functions
40  * \ref ParticleTracer::handleSurfaceInteraction and
41  * \ref ParticleTracer::handleMediumInteraction.
42  *
43  * \ingroup librender
44  */
46 public:
47  /// The particle tracer supports two principal modes of operation
48  enum EMode {
49  /**
50  * \brief Trace a fixed number of \a particles
51  *
52  * In this mode, a specified number of particles will be emitted, and
53  * a customizable action is performed for every scattering event.
54  * Note that the number of resulting \a events will generally be
55  * different from the number of traced \a particles.
56  *
57  * This mode is used for instance by the \c ptracer plugin.
58  */
59  ETrace = 0,
60 
61  /**
62  * \brief `Gather' a fixed number of scattering \a events
63  *
64  * In this mode, the number of particles to be emitted is
65  * unknown ahead of time. Instead, the implementation traces
66  * particles until a a certain number of scattering events
67  * have been recorded.
68  *
69  * This mode is used to create photon maps. See
70  * \ref GatherPhotonProcess for an implementation.
71  */
72  EGather
73  };
74 
75  // =============================================================
76  //! @{ \name Implementation of the ParallelProcess interface
77  // =============================================================
78 
79  virtual EStatus generateWork(WorkUnit *unit, int worker);
80 
81  //! @}
82  // =============================================================
83 
85 protected:
86 
87  /**
88  * Create a new particle process
89  *
90  * \param mode
91  * Particle tracing mode - see above
92  * \param workCount
93  * Total # of particles to trace / # events to record
94  * \param granularity
95  * Number of particles in each work unit. When set to zero,
96  * a suitable number will be automatically chosen.
97  * \param progressText
98  * Title of the progress bar
99  * \param progressReporterPayload
100  * Custom pointer payload to be delivered with progress messages
101  */
102  ParticleProcess(EMode mode, size_t workCount,
103  size_t granularity, const std::string &progressText,
104  const void *progressReporterPayload);
105 
106  void increaseResultCount(size_t resultCount);
107 
108  /// Virtual destructor
109  virtual ~ParticleProcess();
110 protected:
111  EMode m_mode;
112  ProgressReporter *m_progress;
113  size_t m_workCount;
114  size_t m_numGenerated;
115  size_t m_granularity;
116  ref<Mutex> m_resultMutex;
117  size_t m_receivedResultCount;
118 };
119 
120 /**
121  * \brief Abstract particle tracer implementation
122  *
123  * Traces particles and performs a customizable action every time a
124  * surface or volume interaction occurs.
125  *
126  * \ingroup librender
127  */
129 public:
130  // =============================================================
131  //! @{ \name Implementation of the WorkProcessor interface
132  // =============================================================
133 
134  virtual ref<WorkUnit> createWorkUnit() const;
135  virtual void prepare();
136  virtual void process(const WorkUnit *workUnit, WorkResult *workResult,
137  const bool &stop);
138  void serialize(Stream *stream, InstanceManager *manager) const;
139 
140  //! @}
141  // =============================================================
142 
143  /**
144  * \brief Handle a particle emission event
145  *
146  * To be overridden in a subclass. The default implementation
147  * does nothing
148  *
149  * \param pRec
150  * Position sampling record associated with the emission event
151  * \param medium
152  * Pointer to the current medium
153  * \param weight
154  * Initial weight/power of the particle
155  */
156  virtual void handleEmission(const PositionSamplingRecord &pRec,
157  const Medium *medium, const Spectrum &weight);
158 
159  /**
160  * \brief Handle a 'new particle generated' event
161  *
162  * To be overridden in a subclass. The default implementation
163  * does nothing.
164  *
165  * Note that this event will only be delivered if
166  * <tt>emissionEvents=false</tt>. In that case, it is a
167  * substitute to let the subclass know that a new particle
168  * was created, but without providing detailed information
169  * about the emission.
170  */
171  virtual void handleNewParticle();
172 
173  /**
174  * \brief Handle a surface interaction event
175  *
176  * To be overridden in a subclass. The default implementation
177  * does nothing
178  *
179  * \param depth
180  * Depth of the interaction in path space (with 1
181  * corresponding to the first bounce)
182  * \param nullInteractions
183  * Specifies how many of these interactions were of type BSDF::ENull
184  * (i.e. index-matched medium transitions)
185  * \param delta
186  * Denotes if the previous scattering event was a degenerate
187  * specular reflection or refraction.
188  * \param its
189  * Associated intersection record
190  * \param medium
191  * Pointer to the current medium \a before the surface
192  * interaction
193  * \param weight
194  * Weight/power of the particle after having gone through
195  * all preceding interactions except for the current surface
196  * interaction.
197  */
198  virtual void handleSurfaceInteraction(int depth, int nullInteractions,
199  bool delta, const Intersection &its, const Medium *medium,
200  const Spectrum &weight);
201 
202  /**
203  * \brief Handle a medium interaction event
204  *
205  * To be overridden in a subclass. The default implementation
206  * does nothing
207  *
208  * \param depth
209  * Depth of the interaction in path space (with 1
210  * corresponding to the first bounce)
211  * \param nullInteractions
212  * Specifies how many of these interactions were of type BSDF::ENull
213  * (i.e. index-matched medium transitions)
214  * \param delta
215  * Denotes if the previous scattering event was a degenerate
216  * specular reflection or refraction.
217  * \param mRec
218  * Associated medium sampling record
219  * \param medium
220  * Pointer to the current medium
221  * \param weight
222  * Weight/power of the particle after having gone through
223  * all preceding interactions except for the current medium
224  * interaction.
225  */
226  virtual void handleMediumInteraction(int depth, int nullInteractions,
227  bool delta, const MediumSamplingRecord &mRec, const Medium *medium,
228  const Vector &wi, const Spectrum &weight);
229 
231 protected:
232  /// Protected constructor
233  ParticleTracer(int maxDepth, int rrDepth, bool emissionEvents);
234  /// Protected constructor
235  ParticleTracer(Stream *stream, InstanceManager *manager);
236  /// Virtual destructor
237  virtual ~ParticleTracer() { }
238 protected:
244 };
245 
247 
248 #endif /* __MITSUBA_RENDER_PARTICLEPROC_H_ */
int m_rrDepth
Definition: particleproc.h:242
Abstract participating medium.
Definition: medium.h:103
Trace message, for extremely verbose debugging.
Definition: formatter.h:29
virtual EStatus generateWork(WorkUnit *unit, int worker)=0
Generate a piece of work.
Generic sampling record for positions.
Definition: common.h:82
Abstract parallelizable task.
Definition: sched.h:197
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Abstract particle tracer implementation.
Definition: particleproc.h:128
bool m_emissionEvents
Definition: particleproc.h:243
EMode
The particle tracer supports two principal modes of operation.
Definition: particleproc.h:48
Abstract work result – represents the result of a processed WorkUnit instance.
Definition: sched.h:80
Abstract work unit – represents a small amount of information that encodes part of a larger processin...
Definition: sched.h:47
Data record for sampling a point on the in-scattering integral of the RTE.
Definition: medium.h:34
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
Reference counting helper.
Definition: ref.h:40
int m_maxDepth
Definition: particleproc.h:241
General-purpose progress reporter.
Definition: statistics.h:287
Definition: fwd.h:96
ref< Scene > m_scene
Definition: particleproc.h:239
Abstract parallel particle tracing process.
Definition: particleproc.h:45
Container for all information related to a surface intersection.
Definition: shape.h:36
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
ref< Sampler > m_sampler
Definition: particleproc.h:240
#define MTS_NAMESPACE_END
Definition: platform.h:138
Thin wrapper around the recursive boost thread lock.
Definition: lock.h:34
Abstract work processor – takes work units and turns them into WorkResult instances.
Definition: sched.h:118