VTK  9.4.20241117
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
80#ifndef vtkOpenGLGPUVolumeRayCastMapper_h
81#define vtkOpenGLGPUVolumeRayCastMapper_h
82#include <map> // For methods
83
85#include "vtkNew.h" // For vtkNew
86#include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
87#include "vtkShader.h" // For methods
88#include "vtkSmartPointer.h" // For smartptr
89#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
90
91VTK_ABI_NAMESPACE_BEGIN
94class vtkOpenGLCamera;
95class vtkOpenGLTransferFunctions2D;
96class vtkOpenGLVolumeGradientOpacityTables;
97class vtkOpenGLVolumeOpacityTables;
98class vtkOpenGLVolumeRGBTables;
100class vtkTextureObject;
101class vtkVolume;
103class vtkVolumeTexture;
105
106class VTKRENDERINGVOLUMEOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLGPUVolumeRayCastMapper
108{
109public:
111
113 {
115 DepthPass = 1
116 };
117
119 void PrintSelf(ostream& os, vtkIndent indent) override;
120
121 // Description:
122 // Low level API to enable access to depth texture in
123 // RenderToTexture mode. It will return either nullptr if
124 // RenderToImage was never turned on or texture captured
125 // the last time RenderToImage was on.
127
128 // Description:
129 // Low level API to enable access to color texture in
130 // RenderToTexture mode. It will return either nullptr if
131 // RenderToImage was never turned on or texture captured
132 // the last time RenderToImage was on.
134
135 // Description:
136 // Low level API to export the depth texture as vtkImageData in
137 // RenderToImage mode.
138 void GetDepthImage(vtkImageData* im) override;
139
140 // Description:
141 // Low level API to export the color texture as vtkImageData in
142 // RenderToImage mode.
143 void GetColorImage(vtkImageData* im) override;
144
145 // Description:
146 // Mapper can have multiple passes and internally it will set
147 // the state. The state can not be set externally explicitly
148 // but can be set indirectly depending on the options set by
149 // the user.
150 vtkGetMacro(CurrentPass, int);
151
152 // Sets a depth texture for this mapper to use
153 // This allows many mappers to use the same
154 // texture reducing GPU usage. If this is set
155 // the standard depth texture code is skipped
156 // The depth texture should be activated
157 // and deactivated outside of this class
159
165 void SetPartitions(unsigned short x, unsigned short y, unsigned short z);
166
176
177 // Description:
178 // Delete OpenGL objects.
179 // \post done: this->OpenGLObjectsCreated==0
180 void ReleaseGraphicsResources(vtkWindow* window) override;
181
182protected:
185
187
188 // Description:
189 // Build vertex and fragment shader for the volume rendering
191 vtkRenderer* ren, vtkVolume* vol, int noOfComponents, int independentComponents);
192
193 // Description:
194 // Build vertex and fragment shader for the volume rendering
196
197 // TODO Take these out as these are no longer needed
198 // Methods called by the AMR Volume Mapper.
199 void PreRender(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
200 double vtkNotUsed(datasetBounds)[6], double vtkNotUsed(scalarRange)[2],
201 int vtkNotUsed(noOfComponents), unsigned int vtkNotUsed(numberOfLevels)) override
202 {
203 }
204
205 // \pre input is up-to-date
206 void RenderBlock(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
207 unsigned int vtkNotUsed(level)) override
208 {
209 }
210
211 void PostRender(vtkRenderer* vtkNotUsed(ren), int vtkNotUsed(noOfComponents)) override {}
212
213 // Description:
214 // Rendering volume on GPU
215 void GPURender(vtkRenderer* ren, vtkVolume* vol) override;
216
217 // Description:
218 // Method that performs the actual rendering given a volume and a shader
220 vtkOpenGLShaderProperty* shaderProperty);
221
222 // Description:
223 // Update the reduction factor of the render viewport (this->ReductionFactor)
224 // according to the time spent in seconds to render the previous frame
225 // (this->TimeToDraw) and a time in seconds allocated to render the next
226 // frame (allocatedTime).
227 // \pre valid_current_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
228 // \pre positive_TimeToDraw: this->TimeToDraw>=0.0
229 // \pre positive_time: allocatedTime>0
230 // \post valid_new_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
231 void ComputeReductionFactor(double allocatedTime);
232
233 // Description:
234 // Returns a reduction ratio for each dimension
235 // This ratio is computed from MaxMemoryInBytes and MaxMemoryFraction so that the total
236 // memory usage of the resampled image, by the returned ratio, does not exceed
237 // `MaxMemoryInBytes * MaxMemoryFraction`
238 // \pre input is up-to-date
239 // \post Aspect ratio of image is always kept
240 // - for a 1D image `ratio[1] == ratio[2] == 1`
241 // - for a 2D image `ratio[0] == ratio[1]` and `ratio[2] == 1`
242 // - for a 3D image `ratio[0] == ratio[1] == ratio[2]`
243 void GetReductionRatio(double* ratio) override;
244
245 // Description:
246 // Empty implementation.
248 vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property)) override
249 {
250 return 1;
251 }
252
254
258
263 std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
264
269 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
270
276 std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
278 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
280 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
282 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
284 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
286 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
288 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
290 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
292 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
294 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
296 std::map<vtkShader::Type, vtkShader*>& shaders, vtkVolume* vol, bool prePass);
297
302
310
313
314public:
316 using VolumeInputMap = std::map<int, vtkVolumeInputHelper>;
318
319private:
320 class vtkInternal;
321 vtkInternal* Impl;
322
323 friend class vtkVolumeTexture;
324
326 void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) = delete;
327};
328
329VTK_ABI_NAMESPACE_END
330#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:108
Allocate and hold a VTK object.
Definition vtkNew.h:167
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
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:130
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270
#define VTK_MARSHALAUTO