VTK  9.3.20240712
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 "vtkInformation.h" // For deprecated function
18#include "vtkOSPRayCache.h" // For common cache infrastructure
19#include "vtkRenderer.h" // For deprecated function
20#include "vtkRendererNode.h"
21#include "vtkRenderingRayTracingModule.h" // For export macro
22
23#include <vector> // for ivars
24
25#ifdef VTKOSPRAY_ENABLE_DENOISER
26#include <OpenImageDenoise/oidn.hpp> // for denoiser structures
27#endif
28
29VTK_ABI_NAMESPACE_BEGIN
35class vtkMatrix4x4;
36class vtkOSPRayRendererNodeInternals;
38
39class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayRendererNode : public vtkRendererNode
40{
41public:
44 void PrintSelf(ostream& os, vtkIndent indent) override;
45
49 void Build(bool prepass) override;
50
54 void Render(bool prepass) override;
55
59 void Invalidate(bool prepass) override;
60
64 virtual void WriteLayer(unsigned char* buffer, float* zbuffer, int buffx, int buffy, int layer);
65
66 // state beyond rendering core...
67
74
76
79 static void SetSamplesPerPixel(int, vtkRenderer* renderer);
80 static int GetSamplesPerPixel(vtkRenderer* renderer);
82
89
91
94 static void SetMaxContribution(double, vtkRenderer* renderer);
95 static double GetMaxContribution(vtkRenderer* renderer);
97
103
105
108 static void SetMaxDepth(int, vtkRenderer* renderer);
109 static int GetMaxDepth(vtkRenderer* renderer);
111
118
120
123 static void SetMinContribution(double, vtkRenderer* renderer);
124 static double GetMinContribution(vtkRenderer* renderer);
126
133
135
138 static void SetRouletteDepth(int, vtkRenderer* renderer);
139 static int GetRouletteDepth(vtkRenderer* renderer);
141
147
149
152 static void SetVarianceThreshold(double, vtkRenderer* renderer);
153 static double GetVarianceThreshold(vtkRenderer* renderer);
155
157
163 static void SetMaxFrames(int, vtkRenderer* renderer);
164 static int GetMaxFrames(vtkRenderer* renderer);
166
168
173 static void SetRendererType(std::string name, vtkRenderer* renderer);
174 static std::string GetRendererType(vtkRenderer* renderer);
176
184
187 static void SetAmbientSamples(int, vtkRenderer* renderer);
188 static int GetAmbientSamples(vtkRenderer* renderer);
190
197
200 static void SetVolumeSamplingRate(double, vtkRenderer* renderer);
201 static double GetVolumeSamplingRate(vtkRenderer* renderer);
203
210
213 static void SetCompositeOnGL(int, vtkRenderer* renderer);
214 static int GetCompositeOnGL(vtkRenderer* renderer);
216
222
225 static void SetNorthPole(double*, vtkRenderer* renderer);
226 static double* GetNorthPole(vtkRenderer* renderer);
228
234
237 static void SetEastPole(double*, vtkRenderer* renderer);
238 static double* GetEastPole(vtkRenderer* renderer);
240
245
247
253
259
262 static void SetViewTime(double, vtkRenderer* renderer);
263 static double GetViewTime(vtkRenderer* renderer);
265
271
274 static void SetTimeCacheSize(int, vtkRenderer* renderer);
275 static int GetTimeCacheSize(vtkRenderer* renderer);
277
281 OSPRenderer GetORenderer() { return this->ORenderer; }
282 void AddLight(OSPLight light) { this->Lights.push_back(light); }
283
287 virtual void* GetBuffer() { return this->Buffer.data(); }
288
292 virtual float* GetZBuffer() { return this->ZBuffer.data(); }
293
294 // Get the last renderer color buffer as an OpenGL texture.
295 virtual int GetColorBufferTextureGL() { return this->ColorBufferTex; }
296
297 // Get the last renderer depth buffer as an OpenGL texture.
298 virtual int GetDepthBufferTextureGL() { return this->DepthBufferTex; }
299
300 // if you want to traverse your children in a specific order
301 // or way override this method
302 void Traverse(int operation) override;
303
310
316
319 static void SetDenoiserThreshold(int, vtkRenderer* renderer);
320 static int GetDenoiserThreshold(vtkRenderer* renderer);
322
324
331 static void SetEnableDenoiser(int, vtkRenderer* renderer);
332 static int GetEnableDenoiser(vtkRenderer* renderer);
334
336 {
341 NumberOfMode
342 };
343
345
356
357 std::vector<OSPGeometricModel> GeometricModels;
358 std::vector<OSPVolumetricModel> VolumetricModels;
359 std::vector<OSPInstance> Instances;
360
361protected:
364
368 void Denoise();
369
370 // internal structures
371 std::vector<float> Buffer;
372 std::vector<float> ZBuffer;
373
376
377 OSPWorld OWorld{ nullptr };
378 OSPRenderer ORenderer{ nullptr };
379 OSPFrameBuffer OFrameBuffer{ nullptr };
380 OSPCamera OCamera{ nullptr };
381 int ImageX, ImageY;
382 std::vector<OSPLight> Lights;
387 bool UseBackplate{ true }; // use bgcolor for pathtracer or use bgcolor light
388 std::vector<float> ODepthBuffer;
393 vtkOSPRayRendererNodeInternals* Internal;
394 std::string PreviousType;
395
396#ifdef VTKOSPRAY_ENABLE_DENOISER
397 oidn::DeviceRef DenoiserDevice;
398 oidn::FilterRef DenoiserFilter;
399#endif
400 bool DenoiserDirty{ true };
401 std::vector<osp::vec4f> ColorBuffer;
402 std::vector<osp::vec3f> NormalBuffer;
403 std::vector<osp::vec3f> AlbedoBuffer;
404 std::vector<osp::vec4f> DenoisedBuffer;
405
407 std::set<OSPWorld> CacheContents;
408
409private:
411 void operator=(const vtkOSPRayRendererNode&) = delete;
412};
413
414VTK_ABI_NAMESPACE_END
415#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:108
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
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 * 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
a node within a VTK scene graph
Definition vtkViewNode.h:31
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270