VTK  9.3.0
vtkOSPRayRendererNode.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
13#ifndef vtkOSPRayRendererNode_h
14#define vtkOSPRayRendererNode_h
15
16#include "RTWrapper/RTWrapper.h" // for handle types
17#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_2_0
18#include "vtkInformation.h"
19#include "vtkOSPRayCache.h" // For common cache infrastructure
20#include "vtkRenderer.h"
21#include "vtkRendererNode.h"
22#include "vtkRenderingRayTracingModule.h" // For export macro
23
24#include <vector> // for ivars
25
26#ifdef VTKOSPRAY_ENABLE_DENOISER
27#include <OpenImageDenoise/oidn.hpp> // for denoiser structures
28#endif
29
30VTK_ABI_NAMESPACE_BEGIN
36class vtkMatrix4x4;
37class vtkOSPRayRendererNodeInternals;
39class vtkRenderer;
40
41class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayRendererNode : public vtkRendererNode
42{
43public:
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
51 void Build(bool prepass) override;
52
56 void Render(bool prepass) override;
57
61 void Invalidate(bool prepass) override;
62
66 virtual void WriteLayer(unsigned char* buffer, float* zbuffer, int buffx, int buffy, int layer);
67
68 // state beyond rendering core...
69
76
78
81 static void SetSamplesPerPixel(int, vtkRenderer* renderer);
82 static int GetSamplesPerPixel(vtkRenderer* renderer);
84
91
93
96 static void SetMaxContribution(double, vtkRenderer* renderer);
97 static double GetMaxContribution(vtkRenderer* renderer);
99
105
107
110 static void SetMaxDepth(int, vtkRenderer* renderer);
111 static int GetMaxDepth(vtkRenderer* renderer);
113
120
122
125 static void SetMinContribution(double, vtkRenderer* renderer);
126 static double GetMinContribution(vtkRenderer* renderer);
128
135
137
140 static void SetRouletteDepth(int, vtkRenderer* renderer);
141 static int GetRouletteDepth(vtkRenderer* renderer);
143
155
157
160 VTK_DEPRECATED_IN_9_2_0("Use vtkVolumeProperty::SetScatteringAnisotropy instead")
161 static void SetVolumeAnisotropy(double value, vtkRenderer* renderer)
162 {
163 if (!renderer)
164 {
165 return;
166 }
167 vtkInformation* info = renderer->GetInformation();
169 };
170 VTK_DEPRECATED_IN_9_2_0("Use vtkVolumeProperty::GetScatteringAnisotropy instead")
171 static double GetVolumeAnisotropy(vtkRenderer* renderer)
172 {
173 constexpr double DEFAULT_VOLUME_ANISOTROPY = 0.0;
174 if (!renderer)
175 {
176 return DEFAULT_VOLUME_ANISOTROPY;
177 }
178 vtkInformation* info = renderer->GetInformation();
179 if (info && info->Has(vtkOSPRayRendererNode::VOLUME_ANISOTROPY()))
180 {
181 return (info->Get(vtkOSPRayRendererNode::VOLUME_ANISOTROPY()));
182 }
183 return DEFAULT_VOLUME_ANISOTROPY;
184 };
186
192
194
197 static void SetVarianceThreshold(double, vtkRenderer* renderer);
198 static double GetVarianceThreshold(vtkRenderer* renderer);
200
202
208 static void SetMaxFrames(int, vtkRenderer* renderer);
209 static int GetMaxFrames(vtkRenderer* renderer);
211
213
218 static void SetRendererType(std::string name, vtkRenderer* renderer);
219 static std::string GetRendererType(vtkRenderer* renderer);
221
229
232 static void SetAmbientSamples(int, vtkRenderer* renderer);
233 static int GetAmbientSamples(vtkRenderer* renderer);
235
242
245 static void SetVolumeSamplingRate(double, vtkRenderer* renderer);
246 static double GetVolumeSamplingRate(vtkRenderer* renderer);
248
255
258 static void SetCompositeOnGL(int, vtkRenderer* renderer);
259 static int GetCompositeOnGL(vtkRenderer* renderer);
261
267
270 static void SetNorthPole(double*, vtkRenderer* renderer);
271 static double* GetNorthPole(vtkRenderer* renderer);
273
279
282 static void SetEastPole(double*, vtkRenderer* renderer);
283 static double* GetEastPole(vtkRenderer* renderer);
285
290
292
298
304
307 static void SetViewTime(double, vtkRenderer* renderer);
308 static double GetViewTime(vtkRenderer* renderer);
310
316
319 static void SetTimeCacheSize(int, vtkRenderer* renderer);
320 static int GetTimeCacheSize(vtkRenderer* renderer);
322
326 OSPRenderer GetORenderer() { return this->ORenderer; }
327 void AddLight(OSPLight light) { this->Lights.push_back(light); }
328
332 virtual void* GetBuffer() { return this->Buffer.data(); }
333
337 virtual float* GetZBuffer() { return this->ZBuffer.data(); }
338
339 // Get the last renderer color buffer as an OpenGL texture.
340 virtual int GetColorBufferTextureGL() { return this->ColorBufferTex; }
341
342 // Get the last renderer depth buffer as an OpenGL texture.
343 virtual int GetDepthBufferTextureGL() { return this->DepthBufferTex; }
344
345 // if you want to traverse your children in a specific order
346 // or way override this method
347 void Traverse(int operation) override;
348
355
361
364 static void SetDenoiserThreshold(int, vtkRenderer* renderer);
365 static int GetDenoiserThreshold(vtkRenderer* renderer);
367
369
376 static void SetEnableDenoiser(int, vtkRenderer* renderer);
377 static int GetEnableDenoiser(vtkRenderer* renderer);
379
381 {
386 NumberOfMode
387 };
388
390
401
402 std::vector<OSPGeometricModel> GeometricModels;
403 std::vector<OSPVolumetricModel> VolumetricModels;
404 std::vector<OSPInstance> Instances;
405
406protected:
409
413 void Denoise();
414
415 // internal structures
416 std::vector<float> Buffer;
417 std::vector<float> ZBuffer;
418
421
422 OSPWorld OWorld{ nullptr };
423 OSPRenderer ORenderer{ nullptr };
424 OSPFrameBuffer OFrameBuffer{ nullptr };
425 OSPCamera OCamera{ nullptr };
426 int ImageX, ImageY;
427 std::vector<OSPLight> Lights;
432 bool UseBackplate{ true }; // use bgcolor for pathtracer or use bgcolor light
433 std::vector<float> ODepthBuffer;
438 vtkOSPRayRendererNodeInternals* Internal;
439 std::string PreviousType;
440
441#ifdef VTKOSPRAY_ENABLE_DENOISER
442 oidn::DeviceRef DenoiserDevice;
443 oidn::FilterRef DenoiserFilter;
444#endif
445 bool DenoiserDirty{ true };
446 std::vector<osp::vec4f> ColorBuffer;
447 std::vector<osp::vec3f> NormalBuffer;
448 std::vector<osp::vec3f> AlbedoBuffer;
449 std::vector<osp::vec4f> DenoisedBuffer;
450
452 std::set<OSPWorld> CacheContents;
453
454private:
456 void operator=(const vtkOSPRayRendererNode&) = delete;
457};
458
459VTK_ABI_NAMESPACE_END
460#endif
#define OSPWorld
Definition RTWrapper.h:20
#define OSPLight
Definition RTWrapper.h:25
#define OSPFrameBuffer
Definition RTWrapper.h:31
#define OSPRenderer
Definition RTWrapper.h:19
#define OSPCamera
Definition RTWrapper.h:24
a simple class to control print indentation
Definition vtkIndent.h:29
Key for double values in vtkInformation.
Key for integer values in vtkInformation.
Key for vtkObjectBase values.
Key for string values in vtkInformation.
Store vtkAlgorithm input/output information.
represent and manipulate 4x4 transformation matrices
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 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...
static void SetVolumeSamplingRate(double, vtkRenderer *renderer)
Convenience method VOLUME_SAMPLING_RATE on a vtkRenderer.
~vtkOSPRayRendererNode() override
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 vtkInformationDoubleKey * VOLUME_SAMPLING_RATE()
the rate of sampling for volumes, higher numbers increase the number of samples.
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.
static double GetVolumeSamplingRate(vtkRenderer *renderer)
Convenience method VOLUME_SAMPLING_RATE 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
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.
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:59
a node within a VTK scene graph
Definition vtkViewNode.h:31
#define VTK_DEPRECATED_IN_9_2_0(reason)
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270