VTK  9.1.0
vtkOSPRayRendererNode.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkOSPRayRendererNode.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
22#ifndef vtkOSPRayRendererNode_h
23#define vtkOSPRayRendererNode_h
24
25#include "RTWrapper/RTWrapper.h" // for handle types
26#include "vtkOSPRayCache.h" // For common cache infrastructure
27#include "vtkRendererNode.h"
28#include "vtkRenderingRayTracingModule.h" // For export macro
29
30#include <vector> // for ivars
31
32#ifdef VTKOSPRAY_ENABLE_DENOISER
33#include <OpenImageDenoise/oidn.hpp> // for denoiser structures
34#endif
35
41class vtkMatrix4x4;
42class vtkOSPRayRendererNodeInternals;
44class vtkRenderer;
45
46class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayRendererNode : public vtkRendererNode
47{
48public:
51 void PrintSelf(ostream& os, vtkIndent indent) override;
52
56 void Build(bool prepass) override;
57
61 void Render(bool prepass) override;
62
66 void Invalidate(bool prepass) override;
67
71 virtual void WriteLayer(unsigned char* buffer, float* zbuffer, int buffx, int buffy, int layer);
72
73 // state beyond rendering core...
74
81
83
86 static void SetSamplesPerPixel(int, vtkRenderer* renderer);
87 static int GetSamplesPerPixel(vtkRenderer* renderer);
89
96
98
101 static void SetMaxContribution(double, vtkRenderer* renderer);
102 static double GetMaxContribution(vtkRenderer* renderer);
104
110
112
115 static void SetMaxDepth(int, vtkRenderer* renderer);
116 static int GetMaxDepth(vtkRenderer* renderer);
118
125
127
130 static void SetMinContribution(double, vtkRenderer* renderer);
131 static double GetMinContribution(vtkRenderer* renderer);
133
140
142
145 static void SetRouletteDepth(int, vtkRenderer* renderer);
146 static int GetRouletteDepth(vtkRenderer* renderer);
148
155
157
160 static void SetVolumeAnisotropy(double, vtkRenderer* renderer);
161 static double GetVolumeAnisotropy(vtkRenderer* renderer);
163
169
171
174 static void SetVarianceThreshold(double, vtkRenderer* renderer);
175 static double GetVarianceThreshold(vtkRenderer* renderer);
177
179
185 static void SetMaxFrames(int, vtkRenderer* renderer);
186 static int GetMaxFrames(vtkRenderer* renderer);
188
190
195 static void SetRendererType(std::string name, vtkRenderer* renderer);
196 static std::string GetRendererType(vtkRenderer* renderer);
198
206
209 static void SetAmbientSamples(int, vtkRenderer* renderer);
210 static int GetAmbientSamples(vtkRenderer* renderer);
212
219
222 static void SetCompositeOnGL(int, vtkRenderer* renderer);
223 static int GetCompositeOnGL(vtkRenderer* renderer);
225
231
234 static void SetNorthPole(double*, vtkRenderer* renderer);
235 static double* GetNorthPole(vtkRenderer* renderer);
237
243
246 static void SetEastPole(double*, vtkRenderer* renderer);
247 static double* GetEastPole(vtkRenderer* renderer);
249
254
256
262
268
271 static void SetViewTime(double, vtkRenderer* renderer);
272 static double GetViewTime(vtkRenderer* renderer);
274
280
283 static void SetTimeCacheSize(int, vtkRenderer* renderer);
284 static int GetTimeCacheSize(vtkRenderer* renderer);
286
290 OSPRenderer GetORenderer() { return this->ORenderer; }
291 void AddLight(OSPLight light) { this->Lights.push_back(light); }
292
296 virtual void* GetBuffer() { return this->Buffer.data(); }
297
301 virtual float* GetZBuffer() { return this->ZBuffer.data(); }
302
303 // Get the last renderer color buffer as an OpenGL texture.
304 virtual int GetColorBufferTextureGL() { return this->ColorBufferTex; }
305
306 // Get the last renderer depth buffer as an OpenGL texture.
307 virtual int GetDepthBufferTextureGL() { return this->DepthBufferTex; }
308
309 // if you want to traverse your children in a specific order
310 // or way override this method
311 void Traverse(int operation) override;
312
319
325
328 static void SetDenoiserThreshold(int, vtkRenderer* renderer);
329 static int GetDenoiserThreshold(vtkRenderer* renderer);
331
333
340 static void SetEnableDenoiser(int, vtkRenderer* renderer);
341 static int GetEnableDenoiser(vtkRenderer* renderer);
343
345 {
350 NumberOfMode
351 };
352
354
365
366 std::vector<OSPGeometricModel> GeometricModels;
367 std::vector<OSPVolumetricModel> VolumetricModels;
368 std::vector<OSPInstance> Instances;
369
370protected:
373
377 void Denoise();
378
379 // internal structures
380 std::vector<float> Buffer;
381 std::vector<float> ZBuffer;
382
385
386 OSPWorld OWorld{ nullptr };
387 OSPRenderer ORenderer{ nullptr };
388 OSPFrameBuffer OFrameBuffer{ nullptr };
389 OSPCamera OCamera{ nullptr };
390 int ImageX, ImageY;
391 std::vector<OSPLight> Lights;
396 bool UseBackplate{ true }; // use bgcolor for pathtracer or use bgcolor light
397 std::vector<float> ODepthBuffer;
402 vtkOSPRayRendererNodeInternals* Internal;
403 std::string PreviousType;
404
405#ifdef VTKOSPRAY_ENABLE_DENOISER
406 oidn::DeviceRef DenoiserDevice;
407 oidn::FilterRef DenoiserFilter;
408#endif
409 bool DenoiserDirty{ true };
410 std::vector<osp::vec4f> ColorBuffer;
411 std::vector<osp::vec3f> NormalBuffer;
412 std::vector<osp::vec3f> AlbedoBuffer;
413 std::vector<osp::vec4f> DenoisedBuffer;
414
416 std::set<OSPWorld> CacheContents;
417
418private:
420 void operator=(const vtkOSPRayRendererNode&) = delete;
421};
422
423#endif
#define OSPWorld
Definition: RTWrapper.h:17
#define OSPLight
Definition: RTWrapper.h:22
#define OSPFrameBuffer
Definition: RTWrapper.h:28
#define OSPRenderer
Definition: RTWrapper.h:16
#define OSPCamera
Definition: RTWrapper.h:21
a simple class to control print indentation
Definition: vtkIndent.h:113
Key for double values in vtkInformation.
Key for integer values in vtkInformation.
Key for vtkObjectBase values.
Key for string values in vtkInformation.
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:145
temporal cache ospray structures to speed flipbooks
a collection of materials for vtk apps to draw from
links vtkRenderers to OSPRay
static void SetMaxFrames(int, vtkRenderer *renderer)
When present on renderer, controls the number of ospray render calls for each refresh.
static void SetVolumeAnisotropy(double, vtkRenderer *renderer)
Convenience method to set/get VOLUME_ANISOTROPY on a vtkRenderer.
static double GetVarianceThreshold(vtkRenderer *renderer)
Convenience method to set/get VARIANCE_THRESHOLD on a vtkRenderer.
static void SetRendererType(std::string name, vtkRenderer *renderer)
Set the OSPRay renderer type to use (e.g.
static vtkOSPRayRendererNode * GetRendererNode(vtkViewNode *)
Convenience method to get and downcast renderable.
std::vector< osp::vec3f > NormalBuffer
std::vector< float > Buffer
RTW::Backend * GetBackend()
static void SetAmbientSamples(int, vtkRenderer *renderer)
Convenience method to set/get AMBIENT_SAMPLES on a vtkRenderer.
virtual float * GetZBuffer()
Get the last rendered ZBuffer.
static int GetRouletteDepth(vtkRenderer *renderer)
Convenience method to set/get ROULETTE_DEPTH on a vtkRenderer.
void Build(bool prepass) override
Builds myself.
static vtkInformationDoubleKey * MIN_CONTRIBUTION()
When present on renderer, sample contributions below this value will be neglected to speedup renderin...
static void SetCompositeOnGL(int, vtkRenderer *renderer)
Convenience method to set/get COMPOSITE_ON_GL on a vtkRenderer.
static vtkInformationDoubleKey * VOLUME_ANISOTROPY()
When present on renderer, affects path traced rendering phase function.
static vtkInformationDoubleKey * MAX_CONTRIBUTION()
When present on renderer, samples are clamped to this value before they are accumulated into the fram...
~vtkOSPRayRendererNode() override
virtual int GetColorBufferTextureGL()
OSPRenderer GetORenderer()
Methods for other nodes to access.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkInformationIntegerKey * SAMPLES_PER_PIXEL()
When present on renderer, controls the number of primary rays shot per pixel default is 1.
std::vector< OSPVolumetricModel > VolumetricModels
std::vector< OSPInstance > Instances
static int GetAmbientSamples(vtkRenderer *renderer)
Convenience method to set/get AMBIENT_SAMPLES on a vtkRenderer.
static void SetMaterialLibrary(vtkOSPRayMaterialLibrary *, vtkRenderer *renderer)
Convenience method to set/get Material library on a renderer.
static void SetVarianceThreshold(double, vtkRenderer *renderer)
Convenience method to set/get VARIANCE_THRESHOLD on a vtkRenderer.
static int GetEnableDenoiser(vtkRenderer *renderer)
Enable denoising (if supported).
static void SetEastPole(double *, vtkRenderer *renderer)
Convenience method to set/get EAST_POLE on a vtkRenderer.
static vtkInformationObjectBaseKey * MATERIAL_LIBRARY()
Material Library attached to the renderer.
static void SetMaxContribution(double, vtkRenderer *renderer)
Convenience method to set/get MAX_CONTRIBUTION on a vtkRenderer.
static void SetMaxDepth(int, vtkRenderer *renderer)
Convenience method to set/get MAX_DEPTH on a vtkRenderer.
static double GetMaxContribution(vtkRenderer *renderer)
Convenience method to set/get MAX_CONTRIBUTION on a vtkRenderer.
vtkOSPRayRendererNodeInternals * Internal
static int GetTimeCacheSize(vtkRenderer *renderer)
Convenience method to set/get TIME_CACHE_SIZE on a vtkRenderer.
static void SetMinContribution(double, vtkRenderer *renderer)
Convenience method to set/get MIN_CONTRIBUTION on a vtkRenderer.
static int GetMaxFrames(vtkRenderer *renderer)
When present on renderer, controls the number of ospray render calls for each refresh.
std::vector< float > ODepthBuffer
static int GetMaxDepth(vtkRenderer *renderer)
Convenience method to set/get MAX_DEPTH on a vtkRenderer.
static vtkInformationIntegerKey * BACKGROUND_MODE()
Control use of the path tracer backplate and environmental background.
static vtkInformationIntegerKey * ROULETTE_DEPTH()
When present on renderer, controls the ray recursion depth at which to start Russian roulette termina...
static BackgroundMode GetBackgroundMode(vtkRenderer *renderer)
Control use of the path tracer backplate and environmental background.
static double GetViewTime(vtkRenderer *renderer)
Convenience method to set/get VIEW_TIME on a vtkRenderer.
static double * GetEastPole(vtkRenderer *renderer)
Convenience method to set/get EAST_POLE on a vtkRenderer.
std::vector< OSPLight > Lights
static vtkInformationIntegerKey * MAX_DEPTH()
When present on renderer, controls the maximum ray recursion depth default is 20.
static std::string GetRendererType(vtkRenderer *renderer)
Set the OSPRay renderer type to use (e.g.
static vtkInformationIntegerKey * TIME_CACHE_SIZE()
Temporal cache size.
vtkOSPRayCache< vtkOSPRayCacheItemObject > * Cache
static void SetDenoiserThreshold(int, vtkRenderer *renderer)
Convenience method to set/get DENOISER_THRESHOLD on a vtkRenderer.
std::vector< float > ZBuffer
virtual void WriteLayer(unsigned char *buffer, float *zbuffer, int buffx, int buffy, int layer)
Put my results into the correct place in the provided pixel buffer.
virtual void * GetBuffer()
Get the last rendered ColorBuffer.
static double GetMinContribution(vtkRenderer *renderer)
Convenience method to set/get MIN_CONTRIBUTION on a vtkRenderer.
std::set< OSPWorld > CacheContents
virtual int GetDepthBufferTextureGL()
static vtkInformationDoubleKey * VARIANCE_THRESHOLD()
When present on renderer, controls the threshold for adaptive accumulation default is 0....
static vtkInformationIntegerKey * COMPOSITE_ON_GL()
used to make the renderer add ospray's content onto GL rendered content on the window
std::vector< osp::vec3f > AlbedoBuffer
void AddLight(OSPLight light)
void Render(bool prepass) override
Traverse graph in ospray's preferred order and render.
static vtkOSPRayMaterialLibrary * GetMaterialLibrary(vtkRenderer *renderer)
Convenience method to set/get Material library on a renderer.
static int GetSamplesPerPixel(vtkRenderer *renderer)
Convenience method to set/get SAMPLES_PER_PIXEL on a vtkRenderer.
static vtkInformationIntegerKey * AMBIENT_SAMPLES()
When present on renderer, controls the number of ambient occlusion samples shot per hit.
std::vector< osp::vec4f > ColorBuffer
static vtkInformationIntegerKey * ENABLE_DENOISER()
Enable denoising (if supported).
static void SetNorthPole(double *, vtkRenderer *renderer)
Convenience method to set/get NORTH_POLE on a vtkRenderer.
static double * GetNorthPole(vtkRenderer *renderer)
Convenience method to set/get NORTH_POLE on a vtkRenderer.
static void SetRouletteDepth(int, vtkRenderer *renderer)
Convenience method to set/get ROULETTE_DEPTH on a vtkRenderer.
static int GetCompositeOnGL(vtkRenderer *renderer)
Convenience method to set/get COMPOSITE_ON_GL on a vtkRenderer.
void Traverse(int operation) override
static vtkOSPRayRendererNode * New()
static void SetViewTime(double, vtkRenderer *renderer)
Convenience method to set/get VIEW_TIME on a vtkRenderer.
void Invalidate(bool prepass) override
Invalidates cached rendering data.
static void SetSamplesPerPixel(int, vtkRenderer *renderer)
Convenience method to set/get SAMPLES_PER_PIXEL on a vtkRenderer.
static double GetVolumeAnisotropy(vtkRenderer *renderer)
Convenience method to set/get VOLUME_ANISOTROPY on a vtkRenderer.
std::vector< osp::vec4f > DenoisedBuffer
static vtkInformationDoubleVectorKey * NORTH_POLE()
World space direction of north pole for gradient and texture background.
void Denoise()
Denoise the colors stored in ColorBuffer and put into Buffer.
std::vector< OSPGeometricModel > GeometricModels
static vtkInformationIntegerKey * MAX_FRAMES()
When present on renderer, controls the number of ospray render calls for each refresh.
static vtkInformationDoubleVectorKey * EAST_POLE()
World space direction of east pole for texture background.
static void SetEnableDenoiser(int, vtkRenderer *renderer)
Convenience method to set/get ENABLE_DENOISER on a vtkRenderer.
static vtkInformationIntegerKey * DENOISER_THRESHOLD()
Accumulation threshold when above which denoising kicks in.
static int GetDenoiserThreshold(vtkRenderer *renderer)
Convenience method to set/get DENOISER_THRESHOLD on a vtkRenderer.
static void SetTimeCacheSize(int, vtkRenderer *renderer)
Convenience method to set/get TIME_CACHE_SIZE on a vtkRenderer.
static vtkInformationStringKey * RENDERER_TYPE()
Set the OSPRay renderer type to use (e.g.
vtkRenderer * GetRenderer()
static vtkInformationDoubleKey * VIEW_TIME()
Requested time to show in a renderer and to lookup in a temporal cache.
static void SetBackgroundMode(BackgroundMode, vtkRenderer *renderer)
Control use of the path tracer backplate and environmental background.
vtkViewNode specialized for vtkRenderers
abstract specification for renderers
Definition: vtkRenderer.h:182
a node within a VTK scene graph
Definition: vtkViewNode.h:39
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287