Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spiral.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_SPIRAL_H_)
21 #define __MITSUBA_RENDER_SPIRAL_H_
22 
24 #include <mitsuba/render/film.h>
25 
26 #define MTS_BLOCK_SIZE 32
27 
29 
30 /**
31  * \brief Block listener callback for use with the \ref Spiral class
32  * \ingroup librender
33  */
35 public:
36  /// Called whenever an image block is acquired
37  virtual void acquireBlockEvent(const ImageBlock *block) = 0;
38 
39  /// Called whenever an image block is released
40  virtual void releaseBlockEvent(const ImageBlock *block) = 0;
41 
42  /// Called when the whole film has changed
43  virtual void filmChangedEvent() = 0;
44 
45  /// Called when rendering is done
46  virtual void finishEvent() = 0;
47 protected:
48  virtual ~BlockListener() {}
49 };
50 
51 /**
52  * \brief Generates a spiral of blocks to be rendered
53  *
54  * \author Adam Arbree
55  * Aug 25, 2005
56  * RayTracer.java
57  * Used with permission.
58  * Copyright 2005 Program of Computer Graphics, Cornell University
59  * \ingroup librender
60  */
61 
63 public:
64  /**
65  * Create a new spiral generator for an image
66  * of the given width and height.
67  */
68  Spiral(const Film *film);
69 
70  /**
71  * Reset the spiral to its initial state
72  */
73  void reset();
74 
75  /**
76  * Add a block listener, which will be notified
77  * whenever a block has been acquired or released.
78  */
79  void addBlockListener(BlockListener *listener);
80 
81  /// Remove a block listener
82  void removeBlockListener(BlockListener *listener);
83 
84  /// Acquire an image block from the spiral (thread-safe)
85  bool acquireBlock(ImageBlock *block);
86 
87  /// Release a finished image block (thread-safe)
88  void releaseBlock(ImageBlock *block);
89 
90  /// Send the finished event even if not all blocks have been processed yet
91  void finish();
92 
93  /// Send events notifying all listeners that the film has changed
94  void notifyFilmChanged();
95 
96  /// Return the list blocks, which are currently being worked on
97  std::vector<ImageBlock *> getActiveBlocks() const;
98 
99  /// Return the maximum block size
100  int getMaxBlockSize() const;
101 
103 protected:
104  /// Virtual destructor
105  virtual ~Spiral();
106 private:
107  int m_activeBlocks;
108  mutable ref<Mutex> m_mutex;
109  std::vector<ImageBlock *> m_openBlocks;
110  std::vector<BlockListener *> m_listeners;
111  ProgressReporter *m_progress;
112 };
113 
115 
116 #endif
Block listener callback for use with the Spiral class.
Definition: spiral.h:34
Generates a spiral of blocks to be rendered.
Definition: spiral.h:62
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Abstract film base class - used to store samples generated by Integrator implementations.
Definition: film.h:37
Reference counting helper.
Definition: ref.h:40
General-purpose progress reporter.
Definition: statistics.h:287
Storage for an image sub-block (a.k.a render bucket)
Definition: imageblock.h:40
Parent of all Mitsuba classes.
Definition: object.h:38
#define MTS_EXPORT_RENDER
Definition: platform.h:109
virtual ~BlockListener()
Definition: spiral.h:48
#define MTS_NAMESPACE_END
Definition: platform.h:138
Thin wrapper around the recursive boost thread lock.
Definition: lock.h:34