VTK  9.0.1
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 =========================================================================*/
63 #ifndef vtkOpenGLGPUVolumeRayCastMapper_h
64 #define vtkOpenGLGPUVolumeRayCastMapper_h
65 #include <map> // For methods
66 
68 #include "vtkNew.h" // For vtkNew
69 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
70 #include "vtkShader.h" // For methods
71 #include "vtkSmartPointer.h" // For smartptr
72 
75 class vtkOpenGLCamera;
76 class vtkOpenGLTransferFunctions2D;
77 class vtkOpenGLVolumeGradientOpacityTables;
78 class vtkOpenGLVolumeOpacityTables;
79 class vtkOpenGLVolumeRGBTables;
80 class vtkShaderProgram;
81 class vtkTextureObject;
82 class vtkVolume;
84 class vtkVolumeTexture;
86 
87 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkOpenGLGPUVolumeRayCastMapper
89 {
90 public:
92 
93  enum Passes
94  {
96  DepthPass = 1
97  };
98 
100  void PrintSelf(ostream& os, vtkIndent indent) override;
101 
102  // Description:
103  // Low level API to enable access to depth texture in
104  // RenderToTexture mode. It will return either nullptr if
105  // RenderToImage was never turned on or texture captured
106  // the last time RenderToImage was on.
107  vtkTextureObject* GetDepthTexture();
108 
109  // Description:
110  // Low level API to enable access to color texture in
111  // RenderToTexture mode. It will return either nullptr if
112  // RenderToImage was never turned on or texture captured
113  // the last time RenderToImage was on.
114  vtkTextureObject* GetColorTexture();
115 
116  // Description:
117  // Low level API to export the depth texture as vtkImageData in
118  // RenderToImage mode.
119  void GetDepthImage(vtkImageData* im) override;
120 
121  // Description:
122  // Low level API to export the color texture as vtkImageData in
123  // RenderToImage mode.
124  void GetColorImage(vtkImageData* im) override;
125 
126  // Description:
127  // Mapper can have multiple passes and internally it will set
128  // the state. The state can not be set externally explicitly
129  // but can be set indirectly depending on the options set by
130  // the user.
131  vtkGetMacro(CurrentPass, int);
132 
133  // Sets a depth texture for this mapper to use
134  // This allows many mappers to use the same
135  // texture reducing GPU usage. If this is set
136  // the standard depth texture code is skipped
137  // The depth texture should be activated
138  // and deactivated outside of this class
139  void SetSharedDepthTexture(vtkTextureObject* nt);
140 
146  void SetPartitions(unsigned short x, unsigned short y, unsigned short z);
147 
156  bool PreLoadData(vtkRenderer* ren, vtkVolume* vol);
157 
158  // Description:
159  // Delete OpenGL objects.
160  // \post done: this->OpenGLObjectsCreated==0
161  void ReleaseGraphicsResources(vtkWindow* window) override;
162 
163 protected:
166 
168 
169  // Description:
170  // Build vertex and fragment shader for the volume rendering
171  void BuildDepthPassShader(
172  vtkRenderer* ren, vtkVolume* vol, int noOfComponents, int independentComponents);
173 
174  // Description:
175  // Build vertex and fragment shader for the volume rendering
176  void BuildShader(vtkRenderer* ren);
177 
178  // TODO Take these out as these are no longer needed
179  // Methods called by the AMR Volume Mapper.
180  void PreRender(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
181  double vtkNotUsed(datasetBounds)[6], double vtkNotUsed(scalarRange)[2],
182  int vtkNotUsed(noOfComponents), unsigned int vtkNotUsed(numberOfLevels)) override
183  {
184  }
185 
186  // \pre input is up-to-date
187  void RenderBlock(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
188  unsigned int vtkNotUsed(level)) override
189  {
190  }
191 
192  void PostRender(vtkRenderer* vtkNotUsed(ren), int vtkNotUsed(noOfComponents)) override {}
193 
194  // Description:
195  // Rendering volume on GPU
196  void GPURender(vtkRenderer* ren, vtkVolume* vol) override;
197 
198  // Description:
199  // Method that performs the actual rendering given a volume and a shader
200  void DoGPURender(vtkRenderer* ren, vtkOpenGLCamera* cam, vtkShaderProgram* shaderProgram,
201  vtkOpenGLShaderProperty* shaderProperty);
202 
203  // Description:
204  // Update the reduction factor of the render viewport (this->ReductionFactor)
205  // according to the time spent in seconds to render the previous frame
206  // (this->TimeToDraw) and a time in seconds allocated to render the next
207  // frame (allocatedTime).
208  // \pre valid_current_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
209  // \pre positive_TimeToDraw: this->TimeToDraw>=0.0
210  // \pre positive_time: allocatedTime>0
211  // \post valid_new_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
212  void ComputeReductionFactor(double allocatedTime);
213 
214  // Description:
215  // Empty implementation.
216  void GetReductionRatio(double* ratio) override { ratio[0] = ratio[1] = ratio[2] = 1.0; }
217 
218  // Description:
219  // Empty implementation.
221  vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property)) override
222  {
223  return 1;
224  }
225 
227 
230  vtkMTimeType GetRenderPassStageMTime(vtkVolume* vol);
231 
235  void GetShaderTemplate(
236  std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
237 
241  void ReplaceShaderValues(
242  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
243 
248  void ReplaceShaderCustomUniforms(
249  std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
250  void ReplaceShaderBase(
251  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
252  void ReplaceShaderTermination(
253  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
254  void ReplaceShaderShading(
255  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
256  void ReplaceShaderCompute(
257  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
258  void ReplaceShaderCropping(
259  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
260  void ReplaceShaderClipping(
261  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
262  void ReplaceShaderMasking(
263  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
264  void ReplaceShaderPicking(
265  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
266  void ReplaceShaderRTT(
267  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
268  void ReplaceShaderRenderPass(
269  std::map<vtkShader::Type, vtkShader*>& shaders, vtkVolume* vol, bool prePass);
270 
274  void SetShaderParametersRenderPass();
275 
283 
286 
287 public:
289  using VolumeInputMap = std::map<int, vtkVolumeInputHelper>;
291 
292 private:
293  class vtkInternal;
294  vtkInternal* Impl;
295 
296  friend class vtkVolumeTexture;
297 
299  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) = delete;
300 };
301 
302 #endif // vtkOpenGLGPUVolumeRayCastMapper_h
abstract interface for implicit functions
virtual void GPURender(vtkRenderer *, vtkVolume *)
Handled in the subclass - the actual render method.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:44
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293
Creates and manages the volume texture rendered by vtkOpenGLGPUVolumeRayCastMapper.
std::map< int, vtkVolumeInputHelper > VolumeInputMap
virtual void GetDepthImage(vtkImageData *)
Low level API to export the depth texture as vtkImageData in RenderToImage mode.
Convenience container for internal structures specific to a volume input.
virtual void GetColorImage(vtkImageData *)
Low level API to export the color texture as vtkImageData in RenderToImage mode.
void PreRender(vtkRenderer *vtkNotUsed(ren), vtkVolume *vtkNotUsed(vol), double vtkNotUsed(datasetBounds)[6], double vtkNotUsed(scalarRange)[2], int vtkNotUsed(noOfComponents), unsigned int vtkNotUsed(numberOfLevels)) override
abstract specification for renderers
Definition: vtkRenderer.h:61
represent GPU shader properties
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
OpenGL implementation of volume rendering through ray-casting.
a simple class to control print indentation
Definition: vtkIndent.h:33
topologically and geometrically regular array of data
Definition: vtkImageData.h:41
void RenderBlock(vtkRenderer *vtkNotUsed(ren), vtkVolume *vtkNotUsed(vol), unsigned int vtkNotUsed(level)) override
void PostRender(vtkRenderer *vtkNotUsed(ren), int vtkNotUsed(noOfComponents)) override
represents the common properties for rendering a volume.
abstracts an OpenGL texture object.
create a window for renderers to draw into
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...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
OpenGL camera.
void GetReductionRatio(double *ratio) override
Ray casting performed on the GPU.
static vtkGPUVolumeRayCastMapper * New()
vtkNew< vtkInformation > LastRenderPassInfo
Caches the vtkOpenGLRenderPass::RenderPasses() information.
The ShaderProgram uses one or more Shader objects.