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 "vtkRenderingVolumeOpenGL2Module.h" // For export macro
20 
22 
23 // Forward declarations
24 class vtkOpenGLCamera;
25 class vtkShaderProgram;
26 class vtkTextureObject;
29 
30 //----------------------------------------------------------------------------
31 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkOpenGLGPUVolumeRayCastMapper :
33 {
34 public:
36 
37  enum Passes
38  {
40  DepthPass = 1
41  };
42 
44  void PrintSelf( ostream& os, vtkIndent indent );
45 
46  // Description:
47  // Low level API to enable access to depth texture in
48  // RenderToTexture mode. It will return either NULL if
49  // RenderToImage was never turned on or texture captured
50  // the last time RenderToImage was on.
51  vtkTextureObject* GetDepthTexture();
52 
53  // Description:
54  // Low level API to enable access to color texture in
55  // RenderToTexture mode. It will return either NULL if
56  // RenderToImage was never turned on or texture captured
57  // the last time RenderToImage was on.
58  vtkTextureObject* GetColorTexture();
59 
60  // Description:
61  // Low level API to export the depth texture as vtkImageData in
62  // RenderToImage mode.
63  void GetDepthImage(vtkImageData* im);
64 
65  // Description:
66  // Low level API to export the color texture as vtkImageData in
67  // RenderToImage mode.
68  void GetColorImage(vtkImageData* im);
69 
70  // Description:
71  // Mapper can have multiple passes and internally it will set
72  // the state. The state can not be set externally explicitly
73  // but can be set indirectly depending on the options set by
74  // the user.
75  vtkGetMacro(CurrentPass, int);
76 
78 
84  void SetNoiseGenerator(vtkImplicitFunction* generator);
85  vtkSetVector2Macro(NoiseTextureSize, int);
87 
88 protected:
91 
92  // Description:
93  // Delete OpenGL objects.
94  // \post done: this->OpenGLObjectsCreated==0
95  virtual void ReleaseGraphicsResources(vtkWindow *window);
97 
98  // Description:
99  // Build vertex and fragment shader for the volume rendering
100  void BuildDepthPassShader(vtkRenderer* ren, vtkVolume* vol,
101  int noOfComponents,
102  int independentComponents);
103 
104  // Description:
105  // Build vertex and fragment shader for the volume rendering
106  void BuildShader(vtkRenderer* ren, vtkVolume* vol, int noOfCmponents);
107 
108  // TODO Take these out as these are no longer needed
109  // Methods called by the AMR Volume Mapper.
110  virtual void PreRender(vtkRenderer * vtkNotUsed(ren),
111  vtkVolume *vtkNotUsed(vol),
112  double vtkNotUsed(datasetBounds)[6],
113  double vtkNotUsed(scalarRange)[2],
114  int vtkNotUsed(noOfComponents),
115  unsigned int vtkNotUsed(numberOfLevels)) {};
116 
117  // \pre input is up-to-date
118  virtual void RenderBlock(vtkRenderer *vtkNotUsed(ren),
119  vtkVolume *vtkNotUsed(vol),
120  unsigned int vtkNotUsed(level)) {}
121 
122  virtual void PostRender(vtkRenderer *vtkNotUsed(ren),
123  int vtkNotUsed(noOfComponents)) {}
124 
125  // Description:
126  // Rendering volume on GPU
127  void GPURender(vtkRenderer *ren, vtkVolume *vol);
128 
129  // Description:
130  // Method that performs the actual rendering given a volume and a shader
131  void DoGPURender(vtkRenderer* ren,
132  vtkVolume* vol,
133  vtkImageData* input,
134  vtkOpenGLCamera* cam,
135  vtkShaderProgram* shaderProgram,
136  int noOfComponents,
137  int independentComponents);
138 
139  // Description:
140  // Update the reduction factor of the render viewport (this->ReductionFactor)
141  // according to the time spent in seconds to render the previous frame
142  // (this->TimeToDraw) and a time in seconds allocated to render the next
143  // frame (allocatedTime).
144  // \pre valid_current_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
145  // \pre positive_TimeToDraw: this->TimeToDraw>=0.0
146  // \pre positive_time: allocatedTime>0
147  // \post valid_new_reduction_range: this->ReductionFactor>0.0 && this->ReductionFactor<=1.0
148  void ComputeReductionFactor(double allocatedTime);
149 
150  // Description:
151  // Empty implementation.
152  void GetReductionRatio(double* ratio)
153  {
154  ratio[0] = ratio[1] = ratio[2] = 1.0;
155  }
156 
157 
158  // Description:
159  // Empty implementation.
160  virtual int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window),
161  vtkVolumeProperty *vtkNotUsed(property))
162  {
163  return 1;
164  }
165 
166  double ReductionFactor;
168 
169 private:
170  class vtkInternal;
171  vtkInternal* Impl;
172 
173  vtkImplicitFunction* NoiseGenerator;
174  int NoiseTextureSize[2];
175 
177  const vtkOpenGLGPUVolumeRayCastMapper&) VTK_DELETE_FUNCTION;
178  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) VTK_DELETE_FUNCTION;
179 };
180 
181 #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:50
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
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:63
virtual void PostRender(vtkRenderer *vtkNotUsed(ren), int vtkNotUsed(noOfComponents))
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
OpenGL subclass that draws the image to the screen.
a simple class to control print indentation
Definition: vtkIndent.h:39
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
represents the common properties for rendering a volume.
abstracts an OpenGL texture object.
create a window for renderers to draw into
virtual void PreRender(vtkRenderer *vtkNotUsed(ren), vtkVolume *vtkNotUsed(vol), double vtkNotUsed(datasetBounds)[6], double vtkNotUsed(scalarRange)[2], int vtkNotUsed(noOfComponents), unsigned int vtkNotUsed(numberOfLevels))
virtual int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window), vtkVolumeProperty *vtkNotUsed(property))
Based on hardware and properties, we may or may not be able to render using 3D texture mapping...
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
void ReleaseGraphicsResources(vtkWindow *)
Release any graphics resources that are being consumed by this mapper.
virtual void RenderBlock(vtkRenderer *vtkNotUsed(ren), vtkVolume *vtkNotUsed(vol), unsigned int vtkNotUsed(level))
OpenGL camera.
Ray casting performed on the GPU.
static vtkGPUVolumeRayCastMapper * New()
The ShaderProgram uses one or more Shader objects.