Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderjob.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_RENDERJOB_H_)
21 #define __MITSUBA_RENDER_RENDERJOB_H_
22 
23 #include <mitsuba/render/scene.h>
25 
27 
28 /**
29  * \brief Coordinates the process of rendering a single image.
30  *
31  * Implemented as a thread so that multiple jobs can
32  * be executed concurrently.
33  *
34  * \ingroup librender
35  * \ingroup libpython
36  */
38 public:
39  /**
40  * \brief Create a new render job for the given scene.
41  *
42  * When the Resource ID parameters (\c sceneResID, \c sensorResID, ..) are
43  * set to \c -1, the implementation will automatically register the
44  * associated objects (scene, sensor, sampler) with the scheduler and
45  * forward copies to all involved network rendering workers. When some
46  * of these resources have already been registered with
47  * the scheduler, their IDs can be provided to avoid this extra
48  * communication cost.
49  *
50  * \param threadName
51  * Thread name identifier for this render job
52  * \param scene
53  * Scene to be rendered
54  * \param queue
55  * Pointer to a queue, to which this job should be added
56  * \param sceneResID
57  * Resource ID of \c scene (or \c -1)
58  * \param sensorResID
59  * Resource ID of \c scene->getSensor() (or \c -1)
60  * \param samplerResID
61  * Resource ID of the sample generator (or \c -1)
62  * \param threadIsCritical
63  * When set to \c true, the entire program will terminate
64  * if this thread fails unexpectedly.
65  * \param interactive
66  * Are partial results of the rendering process visible, e.g. in
67  * a graphical user interface?
68  */
69  RenderJob(const std::string &threadName,
70  Scene *scene, RenderQueue *queue,
71  int sceneResID = -1,
72  int sensorResID = -1,
73  int samplerResID = -1,
74  bool threadIsCritical = true,
75  bool interactive = false);
76 
77  /// Write out the current (partially rendered) image
78  inline void flush() { m_scene->flush(m_queue, this); }
79 
80  /// Cancel a running render job
81  inline void cancel() { m_scene->cancel(); }
82 
83  /// Wait for the job to finish and return whether it was successful
84  inline bool wait() { join(); return !m_cancelled; }
85 
86  /**
87  * \brief Are partial results of the rendering process visible, e.g. in
88  * a graphical user interface?
89  *
90  * Some integrators may choose to invest more time on generating high-quality
91  * intermediate results in this case.
92  */
93  inline bool isInteractive() const { return m_interactive; }
94 
95  /// Define whether or not this is an interactive job
96  inline void setInteractive(bool interactive) { m_interactive = interactive; }
97 
98  /// Get a pointer to the underlying scene
99  inline Scene *getScene() { return m_scene.get(); }
100 
101  /// Get a pointer to the underlying scene (const version)
102  inline const Scene *getScene() const { return m_scene.get(); }
103 
104  /// Get a pointer to the underlying render queue
105  inline RenderQueue *getRenderQueue() { return m_queue.get(); }
106 
107  /// Get a pointer to the underlying render queue (const version)
108  inline const RenderQueue *getRenderQueue() const { return m_queue.get(); }
109 
110  /// Return the amount of time spent rendering the given job (in seconds)
111  inline Float getRenderTime() const { return m_queue->getRenderTime(this); }
112 
114 protected:
115  /// Virtual destructor
116  virtual ~RenderJob();
117  /// Run method
118  void run();
119 private:
120  ref<Scene> m_scene;
121  ref<RenderQueue> m_queue;
122  int m_sceneResID, m_samplerResID, m_sensorResID;
123  bool m_ownsSceneResource;
124  bool m_ownsSensorResource;
125  bool m_ownsSamplerResource;
126  bool m_cancelled;
127  bool m_interactive;
128 };
129 
131 
132 #endif /* __MITSUBA_RENDER_RENDERJOB_H_ */
bool isInteractive() const
Are partial results of the rendering process visible, e.g. in a graphical user interface?
Definition: renderjob.h:93
void setInteractive(bool interactive)
Define whether or not this is an interactive job.
Definition: renderjob.h:96
const RenderQueue * getRenderQueue() const
Get a pointer to the underlying render queue (const version)
Definition: renderjob.h:108
Principal scene data structure.
Definition: scene.h:49
Render queue - used to keep track of a number of scenes that are simultaneously being rendered...
Definition: renderqueue.h:65
Scene * getScene()
Get a pointer to the underlying scene.
Definition: renderjob.h:99
void cancel()
Cancel a running render job.
Definition: renderjob.h:81
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
void join()
Wait until the thread finishes.
void flush()
Write out the current (partially rendered) image.
Definition: renderjob.h:78
#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
Float getRenderTime() const
Return the amount of time spent rendering the given job (in seconds)
Definition: renderjob.h:111
Cross-platform thread implementation.
Definition: thread.h:34
RenderQueue * getRenderQueue()
Get a pointer to the underlying render queue.
Definition: renderjob.h:105
bool wait()
Wait for the job to finish and return whether it was successful.
Definition: renderjob.h:84
Coordinates the process of rendering a single image.
Definition: renderjob.h:37
const Scene * getScene() const
Get a pointer to the underlying scene (const version)
Definition: renderjob.h:102
#define MTS_EXPORT_RENDER
Definition: platform.h:109
#define MTS_NAMESPACE_END
Definition: platform.h:138