VTK  9.2.6
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 =========================================================================*/
69 #ifndef vtkOpenGLGPUVolumeRayCastMapper_h
70 #define vtkOpenGLGPUVolumeRayCastMapper_h
71 #include <map> // For methods
72 
74 #include "vtkNew.h" // For vtkNew
75 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
76 #include "vtkShader.h" // For methods
77 #include "vtkSmartPointer.h" // For smartptr
78 
81 class vtkOpenGLCamera;
82 class vtkOpenGLTransferFunctions2D;
83 class vtkOpenGLVolumeGradientOpacityTables;
84 class vtkOpenGLVolumeOpacityTables;
85 class vtkOpenGLVolumeRGBTables;
86 class vtkShaderProgram;
87 class vtkTextureObject;
88 class vtkVolume;
90 class vtkVolumeTexture;
92 
93 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkOpenGLGPUVolumeRayCastMapper
95 {
96 public:
98 
99  enum Passes
100  {
102  DepthPass = 1
103  };
104 
106  void PrintSelf(ostream& os, vtkIndent indent) override;
107 
108  // Description:
109  // Low level API to enable access to depth texture in
110  // RenderToTexture mode. It will return either nullptr if
111  // RenderToImage was never turned on or texture captured
112  // the last time RenderToImage was on.
113  vtkTextureObject* GetDepthTexture();
114 
115  // Description:
116  // Low level API to enable access to color texture in
117  // RenderToTexture mode. It will return either nullptr if
118  // RenderToImage was never turned on or texture captured
119  // the last time RenderToImage was on.
120  vtkTextureObject* GetColorTexture();
121 
122  // Description:
123  // Low level API to export the depth texture as vtkImageData in
124  // RenderToImage mode.
125  void GetDepthImage(vtkImageData* im) override;
126 
127  // Description:
128  // Low level API to export the color texture as vtkImageData in
129  // RenderToImage mode.
130  void GetColorImage(vtkImageData* im) override;
131 
132  // Description:
133  // Mapper can have multiple passes and internally it will set
134  // the state. The state can not be set externally explicitly
135  // but can be set indirectly depending on the options set by
136  // the user.
137  vtkGetMacro(CurrentPass, int);
138 
139  // Sets a depth texture for this mapper to use
140  // This allows many mappers to use the same
141  // texture reducing GPU usage. If this is set
142  // the standard depth texture code is skipped
143  // The depth texture should be activated
144  // and deactivated outside of this class
145  void SetSharedDepthTexture(vtkTextureObject* nt);
146 
152  void SetPartitions(unsigned short x, unsigned short y, unsigned short z);
153 
162  bool PreLoadData(vtkRenderer* ren, vtkVolume* vol);
163 
164  // Description:
165  // Delete OpenGL objects.
166  // \post done: this->OpenGLObjectsCreated==0
167  void ReleaseGraphicsResources(vtkWindow* window) override;
168 
169 protected:
172 
174 
175  // Description:
176  // Build vertex and fragment shader for the volume rendering
177  void BuildDepthPassShader(
178  vtkRenderer* ren, vtkVolume* vol, int noOfComponents, int independentComponents);
179 
180  // Description:
181  // Build vertex and fragment shader for the volume rendering
182  void BuildShader(vtkRenderer* ren);
183 
184  // TODO Take these out as these are no longer needed
185  // Methods called by the AMR Volume Mapper.
186  void PreRender(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
187  double vtkNotUsed(datasetBounds)[6], double vtkNotUsed(scalarRange)[2],
188  int vtkNotUsed(noOfComponents), unsigned int vtkNotUsed(numberOfLevels)) override
189  {
190  }
191 
192  // \pre input is up-to-date
193  void RenderBlock(vtkRenderer* vtkNotUsed(ren), vtkVolume* vtkNotUsed(vol),
194  unsigned int vtkNotUsed(level)) override
195  {
196  }
197 
198  void PostRender(vtkRenderer* vtkNotUsed(ren), int vtkNotUsed(noOfComponents)) override {}
199 
200  // Description:
201  // Rendering volume on GPU
202  void GPURender(vtkRenderer* ren, vtkVolume* vol) override;
203 
204  // Description:
205  // Method that performs the actual rendering given a volume and a shader
206  void DoGPURender(vtkRenderer* ren, vtkOpenGLCamera* cam, vtkShaderProgram* shaderProgram,
207  vtkOpenGLShaderProperty* shaderProperty);
208 
209  // Description:
210  // Update the reduction factor of the render viewport (this->ReductionFactor)
211  // according to the time spent in seconds to render the previous frame
212  // (this->TimeToDraw) and a time in seconds allocated to render the next
213  // frame (allocatedTime).
214  // \pre valid_current_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
215  // \pre positive_TimeToDraw: this->TimeToDraw>=0.0
216  // \pre positive_time: allocatedTime>0
217  // \post valid_new_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
218  void ComputeReductionFactor(double allocatedTime);
219 
220  // Description:
221  // Empty implementation.
222  void GetReductionRatio(double* ratio) override { ratio[0] = ratio[1] = ratio[2] = 1.0; }
223 
224  // Description:
225  // Empty implementation.
227  vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property)) override
228  {
229  return 1;
230  }
231 
233 
236  vtkMTimeType GetRenderPassStageMTime(vtkVolume* vol);
237 
241  void GetShaderTemplate(
242  std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
243 
247  void ReplaceShaderValues(
248  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
249 
254  void ReplaceShaderCustomUniforms(
255  std::map<vtkShader::Type, vtkShader*>& shaders, vtkOpenGLShaderProperty* p);
256  void ReplaceShaderBase(
257  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
258  void ReplaceShaderTermination(
259  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
260  void ReplaceShaderShading(
261  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
262  void ReplaceShaderCompute(
263  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
264  void ReplaceShaderCropping(
265  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
266  void ReplaceShaderClipping(
267  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
268  void ReplaceShaderMasking(
269  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
270  void ReplaceShaderPicking(
271  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
272  void ReplaceShaderRTT(
273  std::map<vtkShader::Type, vtkShader*>& shaders, vtkRenderer* ren, vtkVolume* vol, int numComps);
274  void ReplaceShaderRenderPass(
275  std::map<vtkShader::Type, vtkShader*>& shaders, vtkVolume* vol, bool prePass);
276 
280  void SetShaderParametersRenderPass();
281 
289 
292 
293 public:
295  using VolumeInputMap = std::map<int, vtkVolumeInputHelper>;
297 
298 private:
299  class vtkInternal;
300  vtkInternal* Impl;
301 
302  friend class vtkVolumeTexture;
303 
305  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) = delete;
306 };
307 
308 #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:50
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
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:72
represent GPU shader properties
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
OpenGL implementation of volume rendering through ray-casting.
a simple class to control print indentation
Definition: vtkIndent.h:39
topologically and geometrically regular array of data
Definition: vtkImageData.h:53
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.