VTK  9.3.0
vtkOpenGLGPUVolumeRayCastMapper.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
58#ifndef vtkOpenGLGPUVolumeRayCastMapper_h
59#define vtkOpenGLGPUVolumeRayCastMapper_h
60#include <map> // For methods
61
63#include "vtkNew.h" // For vtkNew
64#include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
65#include "vtkShader.h" // For methods
66#include "vtkSmartPointer.h" // For smartptr
67
68VTK_ABI_NAMESPACE_BEGIN
71class vtkOpenGLCamera;
72class vtkOpenGLTransferFunctions2D;
73class vtkOpenGLVolumeGradientOpacityTables;
74class vtkOpenGLVolumeOpacityTables;
75class vtkOpenGLVolumeRGBTables;
78class vtkVolume;
82
83class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkOpenGLGPUVolumeRayCastMapper
85{
86public:
88
89 enum Passes
90 {
92 DepthPass = 1
93 };
94
96 void PrintSelf(ostream& os, vtkIndent indent) override;
97
98 // Description:
99 // Low level API to enable access to depth texture in
100 // RenderToTexture mode. It will return either nullptr if
101 // RenderToImage was never turned on or texture captured
102 // the last time RenderToImage was on.
104
105 // Description:
106 // Low level API to enable access to color texture in
107 // RenderToTexture mode. It will return either nullptr if
108 // RenderToImage was never turned on or texture captured
109 // the last time RenderToImage was on.
111
112 // Description:
113 // Low level API to export the depth texture as vtkImageData in
114 // RenderToImage mode.
115 void GetDepthImage(vtkImageData* im) override;
116
117 // Description:
118 // Low level API to export the color texture as vtkImageData in
119 // RenderToImage mode.
120 void GetColorImage(vtkImageData* im) override;
121
122 // Description:
123 // Mapper can have multiple passes and internally it will set
124 // the state. The state can not be set externally explicitly
125 // but can be set indirectly depending on the options set by
126 // the user.
127 vtkGetMacro(CurrentPass, int);
128
129 // Sets a depth texture for this mapper to use
130 // This allows many mappers to use the same
131 // texture reducing GPU usage. If this is set
132 // the standard depth texture code is skipped
133 // The depth texture should be activated
134 // and deactivated outside of this class
136
142 void SetPartitions(unsigned short x, unsigned short y, unsigned short z);
143
153
154 // Description:
155 // Delete OpenGL objects.
156 // \post done: this->OpenGLObjectsCreated==0
157 void ReleaseGraphicsResources(vtkWindow* window) override;
158
159protected:
162
164
165 // Description:
166 // Build vertex and fragment shader for the volume rendering
168 vtkRenderer* ren, vtkVolume* vol, int noOfComponents, int independentComponents);
169
170 // Description:
171 // Build vertex and fragment shader for the volume rendering
173
174 // TODO Take these out as these are no longer needed
175 // Methods called by the AMR Volume Mapper.
176 void PreRender(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
177 double vtkNotUsed(datasetBounds)[6], double vtkNotUsed(scalarRange)[2],
178 int vtkNotUsed(noOfComponents), unsigned int vtkNotUsed(numberOfLevels)) override
179 {
180 }
181
182 // \pre input is up-to-date
183 void RenderBlock(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
184 unsigned int vtkNotUsed(level)) override
185 {
186 }
187
188 void PostRender(vtkRenderer* vtkNotUsed(ren), int vtkNotUsed(noOfComponents)) override {}
189
190 // Description:
191 // Rendering volume on GPU
192 void GPURender(vtkRenderer* ren, vtkVolume* vol) override;
193
194 // Description:
195 // Method that performs the actual rendering given a volume and a shader
197 vtkOpenGLShaderProperty* shaderProperty);
198
199 // Description:
200 // Update the reduction factor of the render viewport (this->ReductionFactor)
201 // according to the time spent in seconds to render the previous frame
202 // (this->TimeToDraw) and a time in seconds allocated to render the next
203 // frame (allocatedTime).
204 // \pre valid_current_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
205 // \pre positive_TimeToDraw: this->TimeToDraw>=0.0
206 // \pre positive_time: allocatedTime>0
207 // \post valid_new_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
208 void ComputeReductionFactor(double allocatedTime);
209
210 // Description:
211 // Returns a reduction ratio for each dimension
212 // This ratio is computed from MaxMemoryInBytes and MaxMemoryFraction so that the total
213 // memory usage of the resampled image, by the returned ratio, does not exceed
214 // `MaxMemoryInBytes * MaxMemoryFraction`
215 // \pre input is up-to-date
216 // \post Aspect ratio of image is always kept
217 // - for a 1D image `ratio[1] == ratio[2] == 1`
218 // - for a 2D image `ratio[0] == ratio[1]` and `ratio[2] == 1`
219 // - for a 3D image `ratio[0] == ratio[1] == ratio[2]`
220 void GetReductionRatio(double* ratio) override;
221
222 // Description:
223 // Empty implementation.
225 vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property)) override
226 {
227 return 1;
228 }
229
231
235
240 std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
241
246 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
247
253 std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
255 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
257 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
259 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
261 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
263 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
265 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
267 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
269 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
271 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
273 std::map<vtkShader::Type, vtkShader*>& shaders, vtkVolume* vol, bool prePass);
274
279
287
290
291public:
293 using VolumeInputMap = std::map<int, vtkVolumeInputHelper>;
295
296private:
297 class vtkInternal;
298 vtkInternal* Impl;
299
300 friend class vtkVolumeTexture;
301
303 void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) = delete;
304};
305
306VTK_ABI_NAMESPACE_END
307#endif // vtkOpenGLGPUVolumeRayCastMapper_h
Ray casting performed on the GPU.
topologically and geometrically regular array of data
abstract interface for implicit functions
a simple class to control print indentation
Definition vtkIndent.h:29
Allocate and hold a VTK object.
Definition vtkNew.h:51
OpenGL camera.
OpenGL implementation of volume rendering through ray-casting.
void GetColorImage(vtkImageData *im) override
Low level API to export the color texture as vtkImageData in RenderToImage mode.
void ReplaceShaderRTT(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
void SetShaderParametersRenderPass()
Update parameters from RenderPass.
void PreRender(vtkRenderer *vtkNotUsed(ren), vtkVolume *vtkNotUsed(vol), double vtkNotUsed(datasetBounds)[6], double vtkNotUsed(scalarRange)[2], int vtkNotUsed(noOfComponents), unsigned int vtkNotUsed(numberOfLevels)) override
void ReplaceShaderCustomUniforms(std::map< vtkShader::Type, vtkShader * > &shaders, vtkOpenGLShaderProperty *p)
RenderPass string replacements on shader templates called from ReplaceShaderValues.
void GetShaderTemplate(std::map< vtkShader::Type, vtkShader * > &shaders, vtkOpenGLShaderProperty *p)
Create the basic shader template strings before substitutions.
void GetDepthImage(vtkImageData *im) override
Low level API to export the depth texture as vtkImageData in RenderToImage mode.
void BuildShader(vtkRenderer *ren)
void ReplaceShaderCropping(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
void ReplaceShaderRenderPass(std::map< vtkShader::Type, vtkShader * > &shaders, vtkVolume *vol, bool prePass)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
void DoGPURender(vtkRenderer *ren, vtkOpenGLCamera *cam, vtkShaderProgram *shaderProgram, vtkOpenGLShaderProperty *shaderProperty)
std::map< int, vtkVolumeInputHelper > VolumeInputMap
bool PreLoadData(vtkRenderer *ren, vtkVolume *vol)
Load the volume texture into GPU memory.
void ReplaceShaderTermination(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
void RenderBlock(vtkRenderer *vtkNotUsed(ren), vtkVolume *vtkNotUsed(vol), unsigned int vtkNotUsed(level)) override
void PostRender(vtkRenderer *vtkNotUsed(ren), int vtkNotUsed(noOfComponents)) override
void SetSharedDepthTexture(vtkTextureObject *nt)
void ComputeReductionFactor(double allocatedTime)
void ReplaceShaderPicking(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
void ReplaceShaderBase(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
void GetReductionRatio(double *ratio) override
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void ReplaceShaderClipping(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
vtkMTimeType GetRenderPassStageMTime(vtkVolume *vol)
vtkOpenGLRenderPass API
vtkTextureObject * GetColorTexture()
void ReplaceShaderCompute(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
void ReplaceShaderMasking(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
void BuildDepthPassShader(vtkRenderer *ren, vtkVolume *vol, int noOfComponents, int independentComponents)
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
void SetPartitions(unsigned short x, unsigned short y, unsigned short z)
Set a fixed number of partitions in which to split the volume during rendering.
vtkNew< vtkInformation > LastRenderPassInfo
Caches the vtkOpenGLRenderPass::RenderPasses() information.
vtkTextureObject * GetDepthTexture()
void GPURender(vtkRenderer *ren, vtkVolume *vol) override
Handled in the subclass - the actual render method.
static vtkOpenGLGPUVolumeRayCastMapper * New()
void ReplaceShaderValues(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Perform string replacements on the shader templates.
void ReleaseGraphicsResources(vtkWindow *window) override
Release any graphics resources that are being consumed by this mapper.
void ReplaceShaderShading(std::map< vtkShader::Type, vtkShader * > &shaders, vtkRenderer *ren, vtkVolume *vol, int numComps)
Caches the vtkOpenGLRenderPass::RenderPasses() information.
int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window), vtkVolumeProperty *vtkNotUsed(property)) override
Based on hardware and properties, we may or may not be able to render using 3D texture mapping.
represent GPU shader properties
create a window for renderers to draw into
abstract specification for renderers
Definition vtkRenderer.h:59
The ShaderProgram uses one or more Shader objects.
abstracts an OpenGL texture object.
Convenience container for internal structures specific to a volume input.
represents the common properties for rendering a volume.
Creates and manages the volume texture rendered by vtkOpenGLGPUVolumeRayCastMapper.
represents a volume (data & properties) in a rendered scene
Definition vtkVolume.h:40
window superclass for vtkRenderWindow
Definition vtkWindow.h:25
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270