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=========================================================================*/
88#ifndef vtkOpenGLGPUVolumeRayCastMapper_h
89#define vtkOpenGLGPUVolumeRayCastMapper_h
90#include <map> // For methods
91
93#include "vtkNew.h" // For vtkNew
94#include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
95#include "vtkShader.h" // For methods
96#include "vtkSmartPointer.h" // For smartptr
97
100class vtkOpenGLCamera;
101class vtkOpenGLTransferFunctions2D;
102class vtkOpenGLVolumeGradientOpacityTables;
103class vtkOpenGLVolumeOpacityTables;
104class vtkOpenGLVolumeRGBTables;
105class vtkShaderProgram;
106class vtkTextureObject;
107class vtkVolume;
109class vtkVolumeTexture;
111
112class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkOpenGLGPUVolumeRayCastMapper
114{
115public:
117
119 {
121 DepthPass = 1
122 };
123
125 void PrintSelf(ostream& os, vtkIndent indent) override;
126
127 // Description:
128 // Low level API to enable access to depth texture in
129 // RenderToTexture mode. It will return either nullptr if
130 // RenderToImage was never turned on or texture captured
131 // the last time RenderToImage was on.
133
134 // Description:
135 // Low level API to enable access to color texture in
136 // RenderToTexture mode. It will return either nullptr if
137 // RenderToImage was never turned on or texture captured
138 // the last time RenderToImage was on.
140
141 // Description:
142 // Low level API to export the depth texture as vtkImageData in
143 // RenderToImage mode.
144 void GetDepthImage(vtkImageData* im) override;
145
146 // Description:
147 // Low level API to export the color texture as vtkImageData in
148 // RenderToImage mode.
149 void GetColorImage(vtkImageData* im) override;
150
151 // Description:
152 // Mapper can have multiple passes and internally it will set
153 // the state. The state can not be set externally explicitly
154 // but can be set indirectly depending on the options set by
155 // the user.
156 vtkGetMacro(CurrentPass, int);
157
158 // Sets a depth texture for this mapper to use
159 // This allows many mappers to use the same
160 // texture reducing GPU usage. If this is set
161 // the standard depth texture code is skipped
162 // The depth texture should be activated
163 // and deactivated outside of this class
165
171 void SetPartitions(unsigned short x, unsigned short y, unsigned short z);
172
182
183 // Description:
184 // Delete OpenGL objects.
185 // \post done: this->OpenGLObjectsCreated==0
186 void ReleaseGraphicsResources(vtkWindow* window) override;
187
188protected:
191
193
194 // Description:
195 // Build vertex and fragment shader for the volume rendering
197 vtkRenderer* ren, vtkVolume* vol, int noOfComponents, int independentComponents);
198
199 // Description:
200 // Build vertex and fragment shader for the volume rendering
202
203 // TODO Take these out as these are no longer needed
204 // Methods called by the AMR Volume Mapper.
205 void PreRender(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
206 double vtkNotUsed(datasetBounds)[6], double vtkNotUsed(scalarRange)[2],
207 int vtkNotUsed(noOfComponents), unsigned int vtkNotUsed(numberOfLevels)) override
208 {
209 }
210
211 // \pre input is up-to-date
212 void RenderBlock(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
213 unsigned int vtkNotUsed(level)) override
214 {
215 }
216
217 void PostRender(vtkRenderer* vtkNotUsed(ren), int vtkNotUsed(noOfComponents)) override {}
218
219 // Description:
220 // Rendering volume on GPU
221 void GPURender(vtkRenderer* ren, vtkVolume* vol) override;
222
223 // Description:
224 // Method that performs the actual rendering given a volume and a shader
226 vtkOpenGLShaderProperty* shaderProperty);
227
228 // Description:
229 // Update the reduction factor of the render viewport (this->ReductionFactor)
230 // according to the time spent in seconds to render the previous frame
231 // (this->TimeToDraw) and a time in seconds allocated to render the next
232 // frame (allocatedTime).
233 // \pre valid_current_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
234 // \pre positive_TimeToDraw: this->TimeToDraw>=0.0
235 // \pre positive_time: allocatedTime>0
236 // \post valid_new_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
237 void ComputeReductionFactor(double allocatedTime);
238
239 // Description:
240 // Empty implementation.
241 void GetReductionRatio(double* ratio) override { ratio[0] = ratio[1] = ratio[2] = 1.0; }
242
243 // Description:
244 // Empty implementation.
246 vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property)) override
247 {
248 return 1;
249 }
250
252
256
261 std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
262
267 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
268
274 std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
276 std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
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, vtkVolume* vol, bool prePass);
295
300
308
311
312public:
314 using VolumeInputMap = std::map<int, vtkVolumeInputHelper>;
316
317private:
318 class vtkInternal;
319 vtkInternal* Impl;
320
321 friend class vtkVolumeTexture;
322
324 void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) = delete;
325};
326
327#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
Allocate and hold a VTK object.
Definition: vtkNew.h:165
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:182
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:144
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287