Lumiverse  2.5
A framework for creating lighting control applications
CachingArnoldInterface.h
Go to the documentation of this file.
1 
10 #ifndef _Arnold_CACHE_INTERFACE_H_
11 #define _Arnold_CACHE_INTERFACE_H_
12 
13 #pragma once
14 
15 #include "LumiverseCoreConfig.h"
16 
17 #ifdef USE_ARNOLD_CACHING
18 
19 #include "ArnoldInterface.h"
20 
21 #include "ArnoldParameterVector.h"
22 #include "Compositor.h"
23 #include "ToneMapper.h"
24 #include "EXRLayer.h"
25 #include <thread>
26 #include <algorithm>
27 #include <unordered_map>
28 #include <set>
29 #include <thread>
30 #include <mutex>
31 
32 namespace Lumiverse {
33 
34  class CachingRenderContext
35  {
36  public:
37  CachingRenderContext(Compositor* c, int w, int h);
38  ~CachingRenderContext();
39 
40  void setSize(int w, int h);
41  void render(const set<Device*>& d);
42 
43  Compositor* _compositor;
44  float* _buffer;
45  int _w;
46  int _h;
47  mutex _inUse;
48  };
49 
57  class CachingArnoldInterface : public virtual ArnoldInterface
58  {
59  public:
60  CachingArnoldInterface();
61 
67  void init();
68 
72  void close() override;
73 
74  virtual float getPercentage() override;
75 
80  int render(const std::set<Device *> &devices, int w, int h, int& cid);
81 
85  bool setDims(int w, int h) override;
86 
90  void setCacheDims(int w, int h);
91 
98  void setSamples(int samples) override;
99 
103  void setPath(string path) { _cache_file_path = path; }
104  string getPath() { return _cache_file_path; }
105 
106 #ifdef USE_ARNOLD
107 
110  void setOptionParameter(const std::string &paramName, int val) override;
111  void setOptionParameter(const std::string &paramName, float val) override;
112 #endif
113 
117  void dumpCache();
118 
123  virtual void loadIfUsingCaching(const set<Device*>& devices);
124 
126  float* getBufferForContext(int contextId);
127 
129  void closeContext(int contextId);
130 
131  virtual JSONNode toJSON() override;
132 
133  float getExposure();
134  void setExposure(float e);
135 
136  protected:
137 
138  const static int DEFAULT_WIDTH = 1920;
139  const static int DEFAULT_HEIGHT = 980;
140 
141  //Compositor compositor;
142  ToneMapper tone_mapper;
143 
147  Pixel4 *compositor_output;
148 
152  int load_exr(string& filename);
153 
157  virtual void updateDevicesLayers(const std::set<Device *> &devices);
158 
162  const std::unordered_map<std::string, Device*> getDevicesToUpdate(const std::set<Device *> &devices);
163 
169  std::unordered_map<std::string, Device*> cached_devices;
170 
174  bool force_cache_reload = false;
175 
180  float *m_render_buffer = NULL;
181 
185  int _cache_width;
186 
188  int _cache_height;
189 
191  int _cache_aa_samples;
192 
194  string _cache_file_path;
195 
199  float _exposure;
200 
207  bool optionRequiresCacheReload(const std::string &paramName);
208 
209  /*
210  * \brief Test whether a device parameter has changed such that its cache
211  * basis image should be re-rendered. This can happen on updates to params
212  * such as position, rotation, penumbra angle, and distance.
213  */
214  bool isValidCacheCopy(Device *cached_device, Device *other_device);
215 
219  virtual void setHDROutputBuffer();
220 
224  void saveLayer(EXRLayer* l);
225 
229  void loadCache(const set<Device*>& devices);
230 
231  // Variables for thread safety and parallel rendering of cached images
233  map<string, EXRLayer*> _layers;
234 
236  vector<CachingRenderContext*> _contexts;
237 
239  mutex _updateLock;
240 
242  int _maxThreads;
243  };
244 }
245 
246 #endif // USE_ARNOLD_CACHING
247 
248 #endif // _Arnold_CACHE_INTERFACE_H_
void render()
Render a frame and pass it back to node.
Definition: Dumiverse.cpp:43
void close()
Close the connection to node.
Definition: Dumiverse.cpp:37
void init(const char *jsonPatchStr, const char *filename)
Initializes data structures.
Definition: Dumiverse.cpp:29
float getPercentage()
Gets the progress of current frame as a percentage.
Definition: Dumiverse.cpp:25
Stores a vector used by ArnoldPatch.
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
Implementation of a interface between ArnoldPatch and arnold.