Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gatherproc.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_GATHERPROC_H_)
21 #define __MITSUBA_RENDER_GATHERPROC_H_
22 
25 
27 
28 /**
29  * \brief Process for parallel photon map construction
30  *
31  * Given a number and type (surface/caustic/volume) of photons, this
32  * class distributes the work over an arbitrary number of machines.
33  * \ingroup librender
34  */
36 public:
37  enum EGatherType {
38  /// Surface photons (indirect on diffuse surfaces, last bounce was not through a delta BSDF)
40  /// Caustic photons (indirect on diffuse surfaces, last bounce was through a delta BSDF)
42  /// Surface photons (all of them, even direct illumination)
44  /// Volumetric photons
45  EVolumePhotons
46  };
47 
48  /**
49  * Create a new process for parallel photon gathering
50  * \param type
51  * Specifies the type of requested photons (surface/caustic/volume)
52  * \param photonCount
53  * Specifies the number of requested photons
54  * \param granularity
55  * Size of the internally used work units (in photons)
56  * \param isLocal
57  * Should the parallel process only be executed locally? (sending
58  * photons over the network may be unnecessary and wasteful)
59  * \param autoCancel
60  * Indicates if the gathering process should be canceled if there
61  * are not enough photons generated
62  * \param progressReporterPayload
63  * Custom pointer payload to be delivered with progress messages
64  */
65  GatherPhotonProcess(EGatherType type, size_t photonCount,
66  size_t granularity, int maxDepth, int rrDepth, bool isLocal,
67  bool autoCancel, const void *progressReporterPayload);
68 
69  /**
70  * Once the process has finished, this returns a reference
71  * to the (still unbalanced) photon map
72  */
73  inline PhotonMap *getPhotonMap() { return m_photonMap; }
74 
75  /**
76  * \brief Return the number of discarded photons
77  *
78  * Due to asynchronous processing, some excess photons
79  * will generally be produced. This function returns the number
80  * of excess photons that had to be discarded. If this is too
81  * high, the granularity should be decreased.
82  */
83  inline size_t getExcessPhotons() const { return m_excess; }
84 
85  /**
86  * \brief Lists the nuber of particles that had to be shot
87  * in order to fill the photon map.
88  */
89  inline size_t getShotParticles() const { return m_numShot; }
90 
91  // ======================================================================
92  /// @{ \name ParallelProcess implementation
93  // ======================================================================
94 
95  bool isLocal() const;
97  void processResult(const WorkResult *wr, bool cancelled);
98  EStatus generateWork(WorkUnit *unit, int worker);
99 
100  /// @}
101  // ======================================================================
102 
104 protected:
105  /// Virtual destructor
106  virtual ~GatherPhotonProcess() { }
107 
108  /**
109  * \brief Checks if the configuration of needed, generated and shot
110  * photons indicates an unsuccessful progress of the gathering. This
111  * check is taken from PBRT.
112  */
113  inline bool unsuccessful(size_t needed, size_t gen, size_t shot) {
114  return (gen < needed && (gen == 0 || gen < shot/1024));
115  }
116 protected:
122  bool m_isLocal;
124  size_t m_excess, m_numShot;
125 };
126 
128 
129 #endif /* __MITSUBA_RENDER_GATHERPROC_H_ */
ref< PhotonMap > m_photonMap
Definition: gatherproc.h:118
bool unsuccessful(size_t needed, size_t gen, size_t shot)
Checks if the configuration of needed, generated and shot photons indicates an unsuccessful progress ...
Definition: gatherproc.h:113
int m_rrDepth
Definition: gatherproc.h:121
PhotonMap * getPhotonMap()
Definition: gatherproc.h:73
Process for parallel photon map construction.
Definition: gatherproc.h:35
virtual bool isLocal() const
Is this process strictly local?
size_t m_photonCount
Definition: gatherproc.h:119
int m_maxDepth
Definition: gatherproc.h:120
virtual void processResult(const WorkResult *result, bool cancelled)=0
Called whenever a work unit has been completed.
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
bool m_isLocal
Definition: gatherproc.h:122
Surface photons (all of them, even direct illumination)
Definition: gatherproc.h:43
Caustic photons (indirect on diffuse surfaces, last bounce was through a delta BSDF) ...
Definition: gatherproc.h:41
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
Surface photons (indirect on diffuse surfaces, last bounce was not through a delta BSDF) ...
Definition: gatherproc.h:39
size_t getExcessPhotons() const
Return the number of discarded photons.
Definition: gatherproc.h:83
virtual EStatus generateWork(WorkUnit *unit, int worker)
Generate a piece of work.
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Implementation of the photon map data structure.
Definition: photonmap.h:34
Reference counting helper.
Definition: ref.h:40
bool m_autoCancel
Definition: gatherproc.h:123
size_t m_numShot
Definition: gatherproc.h:124
EGatherType
Definition: gatherproc.h:37
EGatherType m_type
Definition: gatherproc.h:117
virtual ref< WorkProcessor > createWorkProcessor() const =0
Create an instance of the algorithm responsible for executing the work units of this parallel process...
Abstract parallel particle tracing process.
Definition: particleproc.h:45
#define MTS_EXPORT_RENDER
Definition: platform.h:109
size_t getShotParticles() const
Lists the nuber of particles that had to be shot in order to fill the photon map. ...
Definition: gatherproc.h:89
#define MTS_NAMESPACE_END
Definition: platform.h:138