VTK  9.1.0
vtkOpenGLGPUVolumeRayCastMapper.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkOpenGLGPUVolumeRayCastMapper.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=========================================================================*/
79#ifndef vtkOpenGLGPUVolumeRayCastMapper_h
80#define vtkOpenGLGPUVolumeRayCastMapper_h
81#include <map> // For methods
82
84#include "vtkNew.h" // For vtkNew
85#include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
86#include "vtkShader.h" // For methods
87#include "vtkSmartPointer.h" // For smartptr
88
91class vtkOpenGLCamera;
92class vtkOpenGLTransferFunctions2D;
93class vtkOpenGLVolumeGradientOpacityTables;
94class vtkOpenGLVolumeOpacityTables;
95class vtkOpenGLVolumeRGBTables;
98class vtkVolume;
100class vtkVolumeTexture;
102
103class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkOpenGLGPUVolumeRayCastMapper
105{
106public:
108
110 {
112 DepthPass = 1
113 };
114
116 void PrintSelf(ostream& os, vtkIndent indent) override;
117
118 // Description:
119 // Low level API to enable access to depth texture in
120 // RenderToTexture mode. It will return either nullptr if
121 // RenderToImage was never turned on or texture captured
122 // the last time RenderToImage was on.
124
125 // Description:
126 // Low level API to enable access to color texture in
127 // RenderToTexture mode. It will return either nullptr if
128 // RenderToImage was never turned on or texture captured
129 // the last time RenderToImage was on.
131
132 // Description:
133 // Low level API to export the depth texture as vtkImageData in
134 // RenderToImage mode.
135 void GetDepthImage(vtkImageData* im) override;
136
137 // Description:
138 // Low level API to export the color texture as vtkImageData in
139 // RenderToImage mode.
140 void GetColorImage(vtkImageData* im) override;
141
142 // Description:
143 // Mapper can have multiple passes and internally it will set
144 // the state. The state can not be set externally explicitly
145 // but can be set indirectly depending on the options set by
146 // the user.
147 vtkGetMacro(CurrentPass, int);
148
149 // Sets a depth texture for this mapper to use
150 // This allows many mappers to use the same
151 // texture reducing GPU usage. If this is set
152 // the standard depth texture code is skipped
153 // The depth texture should be activated
154 // and deactivated outside of this class
156
162 void SetPartitions(unsigned short x, unsigned short y, unsigned short z);
163
173
174 // Description:
175 // Delete OpenGL objects.
176 // \post done: this->OpenGLObjectsCreated==0
177 void ReleaseGraphicsResources(vtkWindow* window) override;
178
179protected:
182
184
185 // Description:
186 // Build vertex and fragment shader for the volume rendering
188 vtkRenderer* ren, vtkVolume* vol, int noOfComponents, int independentComponents);
189
190 // Description:
191 // Build vertex and fragment shader for the volume rendering
193
194 // TODO Take these out as these are no longer needed
195 // Methods called by the AMR Volume Mapper.
196 void PreRender(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
197 double vtkNotUsed(datasetBounds)[6], double vtkNotUsed(scalarRange)[2],
198 int vtkNotUsed(noOfComponents), unsigned int vtkNotUsed(numberOfLevels)) override
199 {
200 }
201
202 // \pre input is up-to-date
203 void RenderBlock(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
204 unsigned int vtkNotUsed(level)) override
205 {
206 }
207
208 void PostRender(vtkRenderer* vtkNotUsed(ren), int vtkNotUsed(noOfComponents)) override {}
209
210 // Description:
211 // Rendering volume on GPU
212 void GPURender(vtkRenderer* ren, vtkVolume* vol) override;
213
214 // Description:
215 // Method that performs the actual rendering given a volume and a shader
217 vtkOpenGLShaderProperty* shaderProperty);
218
219 // Description:
220 // Update the reduction factor of the render viewport (this->ReductionFactor)
221 // according to the time spent in seconds to render the previous frame
222 // (this->TimeToDraw) and a time in seconds allocated to render the next
223 // frame (allocatedTime).
224 // \pre valid_current_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
225 // \pre positive_TimeToDraw: this->TimeToDraw>=0.0
226 // \pre positive_time: allocatedTime>0
227 // \post valid_new_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
228 void ComputeReductionFactor(double allocatedTime);
229
230 // Description:
231 // Empty implementation.
232 void GetReductionRatio(double* ratio) override { ratio[0] = ratio[1] = ratio[2] = 1.0; }
233
234 // Description:
235 // Empty implementation.
237 vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property)) override
238 {
239 return 1;
240 }
241
243
247
252 std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
253
258 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
259
265 std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
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, vtkRenderer* ren, vtkVolume* vol, int numComps);
275 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
277 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
279 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
281 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
283 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
285 std::map<vtkShader::Type, vtkShader*>& shaders, vtkVolume* vol, bool prePass);
286
291
299
302
303public:
305 using VolumeInputMap = std::map<int, vtkVolumeInputHelper>;
307
308private:
309 class vtkInternal;
310 vtkInternal* Impl;
311
312 friend class vtkVolumeTexture;
313
315 void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) = delete;
316};
317
318#endif // vtkOpenGLGPUVolumeRayCastMapper_h
Ray casting performed on the GPU.
topologically and geometrically regular array of data
Definition: vtkImageData.h:157
abstract interface for implicit functions
a simple class to control print indentation
Definition: vtkIndent.h:113
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 rendring.
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:173
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:134
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
@ level
Definition: vtkX3D.h:401
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287