VTK
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 =========================================================================*/
15 
16 #ifndef vtkOpenGLGPUVolumeRayCastMapper_h
17 #define vtkOpenGLGPUVolumeRayCastMapper_h
18 
19 #include "vtkNew.h" // For vtkNew
20 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
22 
23 // Forward declarations
26 class vtkOpenGLCamera;
27 class vtkShaderProgram;
28 class vtkTextureObject;
29 class vtkVolumeTexture;
30 
31 //----------------------------------------------------------------------------
32 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkOpenGLGPUVolumeRayCastMapper :
34 {
35 public:
37 
38  enum Passes
39  {
41  DepthPass = 1
42  };
43 
45  void PrintSelf( ostream& os, vtkIndent indent ) VTK_OVERRIDE;
46 
47  // Description:
48  // Low level API to enable access to depth texture in
49  // RenderToTexture mode. It will return either NULL if
50  // RenderToImage was never turned on or texture captured
51  // the last time RenderToImage was on.
52  vtkTextureObject* GetDepthTexture();
53 
54  // Description:
55  // Low level API to enable access to color texture in
56  // RenderToTexture mode. It will return either NULL if
57  // RenderToImage was never turned on or texture captured
58  // the last time RenderToImage was on.
59  vtkTextureObject* GetColorTexture();
60 
61  // Description:
62  // Low level API to export the depth texture as vtkImageData in
63  // RenderToImage mode.
64  void GetDepthImage(vtkImageData* im) VTK_OVERRIDE;
65 
66  // Description:
67  // Low level API to export the color texture as vtkImageData in
68  // RenderToImage mode.
69  void GetColorImage(vtkImageData* im) VTK_OVERRIDE;
70 
71  // Description:
72  // Mapper can have multiple passes and internally it will set
73  // the state. The state can not be set externally explicitly
74  // but can be set indirectly depending on the options set by
75  // the user.
76  vtkGetMacro(CurrentPass, int);
77 
79 
85  void SetNoiseGenerator(vtkImplicitFunction* generator);
86  vtkSetVector2Macro(NoiseTextureSize, int);
88 
94  void SetPartitions(unsigned short x, unsigned short y, unsigned short z);
95 
104  bool PreLoadData(vtkRenderer* ren, vtkVolume* vol);
105 
106 protected:
108  ~vtkOpenGLGPUVolumeRayCastMapper() VTK_OVERRIDE;
109 
110  // Description:
111  // Delete OpenGL objects.
112  // \post done: this->OpenGLObjectsCreated==0
113  void ReleaseGraphicsResources(vtkWindow *window) VTK_OVERRIDE;
115 
116  // Description:
117  // Build vertex and fragment shader for the volume rendering
118  void BuildDepthPassShader(vtkRenderer* ren, vtkVolume* vol,
119  int noOfComponents,
120  int independentComponents);
121 
122  // Description:
123  // Build vertex and fragment shader for the volume rendering
124  void BuildShader(vtkRenderer* ren, vtkVolume* vol, int noOfCmponents);
125 
126  // TODO Take these out as these are no longer needed
127  // Methods called by the AMR Volume Mapper.
128  void PreRender(vtkRenderer * vtkNotUsed(ren),
129  vtkVolume *vtkNotUsed(vol),
130  double vtkNotUsed(datasetBounds)[6],
131  double vtkNotUsed(scalarRange)[2],
132  int vtkNotUsed(noOfComponents),
133  unsigned int vtkNotUsed(numberOfLevels)) VTK_OVERRIDE {};
134 
135  // \pre input is up-to-date
136  void RenderBlock(vtkRenderer *vtkNotUsed(ren),
137  vtkVolume *vtkNotUsed(vol),
138  unsigned int vtkNotUsed(level)) VTK_OVERRIDE {}
139 
140  void PostRender(vtkRenderer *vtkNotUsed(ren),
141  int vtkNotUsed(noOfComponents)) VTK_OVERRIDE {}
142 
143  // Description:
144  // Rendering volume on GPU
145  void GPURender(vtkRenderer *ren, vtkVolume *vol) VTK_OVERRIDE;
146 
147  // Description:
148  // Method that performs the actual rendering given a volume and a shader
149  void DoGPURender(vtkRenderer* ren,
150  vtkVolume* vol,
151  vtkOpenGLCamera* cam,
152  vtkShaderProgram* shaderProgram,
153  int noOfComponents,
154  int independentComponents);
155 
156  // Description:
157  // Update the reduction factor of the render viewport (this->ReductionFactor)
158  // according to the time spent in seconds to render the previous frame
159  // (this->TimeToDraw) and a time in seconds allocated to render the next
160  // frame (allocatedTime).
161  // \pre valid_current_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
162  // \pre positive_TimeToDraw: this->TimeToDraw>=0.0
163  // \pre positive_time: allocatedTime>0
164  // \post valid_new_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
165  void ComputeReductionFactor(double allocatedTime);
166 
167  // Description:
168  // Empty implementation.
169  void GetReductionRatio(double* ratio) VTK_OVERRIDE
170  {
171  ratio[0] = ratio[1] = ratio[2] = 1.0;
172  }
173 
174 
175  // Description:
176  // Empty implementation.
177  int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window),
178  vtkVolumeProperty *vtkNotUsed(property)) VTK_OVERRIDE
179  {
180  return 1;
181  }
182 
184 
187  vtkMTimeType GetRenderPassStageMTime(vtkVolume* vol);
188 
192  void ReplaceShaderRenderPass(std::string& vertShader, std::string& fragShader,
193  vtkVolume* vol, bool prePass);
194 
198  void SetShaderParametersRenderPass(vtkVolume* vol);
206 
207  double ReductionFactor;
209 
210 private:
211  class vtkInternal;
212  vtkInternal* Impl;
213 
214  friend class vtkVolumeTexture;
215  vtkVolumeTexture* VolumeTexture;
216 
217  vtkImplicitFunction* NoiseGenerator;
218  int NoiseTextureSize[2];
219 
221  const vtkOpenGLGPUVolumeRayCastMapper&) VTK_DELETE_FUNCTION;
222  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) VTK_DELETE_FUNCTION;
223 };
224 
225 #endif // vtkOpenGLGPUVolumeRayCastMapper_h
abstract interface for implicit functions
virtual void GPURender(vtkRenderer *, vtkVolume *)
Handled in the subclass - the actual render method.
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:44
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:300
Creates and manages the volume texture rendered by vtkOpenGLGPUVolumeRayCastMapper.
virtual void GetDepthImage(vtkImageData *)
Low level API to export the depth texture as vtkImageData in RenderToImage mode.
virtual void GetColorImage(vtkImageData *)
Low level API to export the color texture as vtkImageData in RenderToImage mode.
abstract specification for renderers
Definition: vtkRenderer.h:57
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
OpenGL subclass that draws the image to the screen.
a simple class to control print indentation
Definition: vtkIndent.h:33
topologically and geometrically regular array of data
Definition: vtkImageData.h:39
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.