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 =========================================================================*/
36 #ifndef vtkOpenGLGPUVolumeRayCastMapper_h
37 #define vtkOpenGLGPUVolumeRayCastMapper_h
38 
39 #include "vtkRenderingVolumeOpenGLModule.h" // For export macro
41 
42 class vtkVolume;
43 class vtkRenderer;
45 class vtkMatrix4x4;
46 class vtkUnsupportedRequiredExtensionsStringStream; // Pimpl
47 class vtkMapDataArrayTextureId; // Pimpl
48 class vtkMapMaskTextureId; // Pimpl
49 class vtkPolyData;
51 class vtkClipPolyData;
53 
54 class vtkOpacityTable; // internal class.
55 class vtkRGBTable; // internal class.
56 class vtkKWScalarField; // internal class.
57 class vtkKWMask; // internal class.
58 
59 class vtkOpacityTables; // Pimpl
60 class vtkDensifyPolyData;
61 class vtkStdString;
62 
63 class vtkShaderProgram2;
64 class vtkShader2;
65 
66 class VTKRENDERINGVOLUMEOPENGL_EXPORT vtkOpenGLGPUVolumeRayCastMapper
68 {
69 public:
72  virtual void PrintSelf(ostream& os, vtkIndent indent);
73 
75 
79  virtual int IsRenderSupported(vtkRenderWindow *window,
80  vtkVolumeProperty *property);
82 
84  virtual void ReleaseGraphicsResources(vtkWindow *window);
85 
88  static const char *OpenGLErrorMessage(unsigned int errorCode);
89 
92  static void PrintError(const char *headerMessage);
93 
94 protected:
97 
98  // The render method called by the superclass
99  virtual void GPURender(vtkRenderer *ren,
100  vtkVolume *vol);
101 
102  // Methods called by the AMR Volume Mapper.
103  virtual void PreRender(vtkRenderer *ren,
104  vtkVolume *vol,
105  double datasetBounds[6],
106  double scalarRange[2],
107  int numberOfScalarComponents,
108  unsigned int numberOfLevels);
109 
110  // \pre input is up-to-date
111  virtual void RenderBlock(vtkRenderer *ren,
112  vtkVolume *vol,
113  unsigned int level);
114 
115  virtual void PostRender(vtkRenderer *ren,
116  int numberOfScalarComponents);
117 
119 
123  int TestRequiredExtension(vtkOpenGLExtensionManager *extensions,
124  const char *extensionName);
126 
132  void LoadExtensions(vtkRenderWindow *window);
133 
139  void CreateOpenGLObjects(vtkRenderer *ren);
140 
146  int AllocateFrameBuffers(vtkRenderer *ren);
147 
149 
166  int LoadScalarField(vtkImageData *input,
167  vtkImageData *maskInput,
168  int textureExtent[6],
169  vtkVolume *volume);
171 
173 
177  int UpdateColorTransferFunction(vtkVolume *vol,
178  int numberOfScalarComponents);
180 
181 
185  int UpdateOpacityTransferFunction(vtkVolume *vol,
186  int numberOfScalarComponents,
187  unsigned int level);
189 
192  void SetupRender(vtkRenderer *ren, vtkVolume *vol);
193 
195 
197  void ClipBoundingBox(vtkRenderer *ren,
198  double worldBounds[6],
199  vtkVolume *vol);
201 
203 
206  int RenderClippedBoundingBox(int tcoordFlag,
207  size_t currentBlock,
208  size_t numberOfBlocks,
209  vtkRenderWindow *renWin);
211 
214  void CopyFBOToTexture();
215 
217  void CleanupRender();
218 
220  void RenderTextureToScreen(vtkRenderer *ren);
221 
224  int PowerOfTwoGreaterOrEqual(int x);
225 
227  void CheckFrameBufferStatus();
228 
231  vtkStdString BufferToString(int buffer);
232 
234  void DisplayReadAndDrawBuffers();
235 
237  void DisplayFrameBufferAttachments();
238 
240  void DisplayFrameBufferAttachment(unsigned int uattachment);
241 
243 
248  void BuildProgram(vtkRenderWindow *w,
249  int parallelProjection,
250  int raycastMethod,
251  int shadeMethod,
252  int componentMethod);
254 
256  void GetLightingStatus();
257 
267  void ComputeReductionFactor(double allocatedTime);
268 
270 
271  void RenderWholeVolume(vtkRenderer *ren,
272  vtkVolume *vol);
274 
276 
277  void RenderRegions(vtkRenderer *ren,
278  vtkVolume *vol);
280 
281  // Return abort status (true==abort)
282  int RenderSubVolume(vtkRenderer *ren,
283  double bounds[6],
284  vtkVolume *vol);
285 
286  void LoadProjectionParameters(vtkRenderer *ren,
287  vtkVolume *vol);
288 
290  void ComputeNumberOfCroppingRegions();
291 
292  void GetTextureFormat(vtkImageData *input,
293  unsigned int *internalFormat,
294  unsigned int *format,
295  unsigned int *type,
296  int *componentSize);
297 
298  bool TestLoadingScalar(unsigned int internalFormat,
299  unsigned int format,
300  unsigned int type,
301  int textureSize[3],
302  int componentSize);
303 
304  void SlabsFromDatasetToIndex(double slabsDataSet[6],
305  double slabsPoints[6]);
306 
307  void SlabsFromIndexToDataset(double slabsPoints[6],
308  double slabsDataSet[6]);
309 
310  const char *GetEnabledString(unsigned char value);
311  void GetOpenGLState();
312 
313  void DebugDisplayBox(vtkPolyData *box);
314 
315  void UpdateNoiseTexture();
316 
318 
322  double ComputeMinimalSampleDistancePerPixel(vtkRenderer *renderer,
323  vtkVolume *volume);
325 
334  virtual void GetReductionRatio(double ratio[3]);
335 
337 
338  // World coordinates of each corner of the dataset.
339  double BoundingBox[8][3];
340 
341  // Used during the clipping process.
345 
348 
350 
353 
354  unsigned int FrameBufferObject;
356 
357  // 3D scalar texture +1D color+1D opacity+2D grabbed depth buffer
358  // +1 2D colorbuffer.
359  unsigned int TextureObjects[5];
360  // used in MIP Mode (2 needed for ping-pong technique)
361  unsigned int MaxValueFrameBuffer;
362  unsigned int MaxValueFrameBuffer2;
363  int ReducedSize[2];
364 
366 
367  int LastSize[2];
368 
370 
371  // Supported extensions
372  // List of unsupported required extensions. Pimpl.
373  vtkUnsupportedRequiredExtensionsStringStream *UnsupportedRequiredExtensions;
375 
378 
380 
381  // Matrices used in internal computation. As a member variable,
382  // only one memory allocation is performed.
383  vtkMatrix4x4 *TempMatrix[3];
384 
385  double TableRange[2];
386 
387  // Final string to send to the GPU as the fragment program source code.
388 // char *FragmentCode;
389 // int FragmentCodeCapacity;
390 
393  char *ErrorString;
394 
395  // Store the last projection an raycast method in order to not rebuild
396  // the fragment code at every call.
402 
405 
408  void BuildScaleBiasProgram(vtkRenderWindow *w);
409 
410 #if 0
411  vtkIdType LoadedExtent[6];
412  double LoadedBounds[6];
413  vtkTimeStamp LoadedScalarTime;
414  int LoadedCellFlag; // point data or cell data (or field data, not handled) ?
415 #endif
416 
417  unsigned int SavedFrameBuffer; // some offscreen mode use a framebuffer too.
418 
420 
421  float *NoiseTexture;
422  int NoiseTextureSize; // size of one dimension.
423  unsigned int NoiseTextureId; // GLuint
424 
426 
427  vtkMapDataArrayTextureId *ScalarsTextures; // need a list for AMR mode.
428  vtkMapMaskTextureId *MaskTextures; // need a list for AMR mode.
429 
430  vtkRGBTable *RGBTable;
431  vtkRGBTable *Mask1RGBTable;
432  vtkRGBTable *Mask2RGBTable;
433 
434  vtkOpacityTables *OpacityTables;
435 
436  vtkKWScalarField *CurrentScalar;
437  vtkKWMask *CurrentMask;
438 
440 
441  double LastProgressEventTime; // initial value is 0.0. Expressed in seconds.
442 
444 
452 
453  // Internal Variable used to keep track of whether or render window's size
454  // changed and therefore we need re-allocation.
456 
458 
459 private:
461  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&); // Not implemented.
462 };
463 
464 #endif
GLSL Shader.
Definition: vtkShader2.h:61
virtual void GPURender(vtkRenderer *, vtkVolume *)
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:49
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:38
record modification and/or execution time
Definition: vtkTimeStamp.h:34
maintain a list of planes
abstract specification for renderers
Definition: vtkRenderer.h:62
int vtkIdType
Definition: vtkType.h:247
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
vtkUnsupportedRequiredExtensionsStringStream * UnsupportedRequiredExtensions
OpenGL subclass that draws the image to the screen.
GLSL Program.
a simple class to control print indentation
Definition: vtkIndent.h:38
topologically and geometrically regular array of data
Definition: vtkImageData.h:44
perform various plane computations
Definition: vtkPlane.h:36
virtual void GetReductionRatio(double ratio[3])=0
Interface class for querying and using OpenGL extensions.
represents the common properties for rendering a volume.
clip polygonal data with user-specified implicit function or input scalar data
virtual void RenderBlock(vtkRenderer *ren, vtkVolume *vol, unsigned int level)=0
virtual int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window), vtkVolumeProperty *vtkNotUsed(property))
create a window for renderers to draw into
Densify the input by adding points at the centroid.
Create a polygonal representation of a box with a given level of subdivision.
void PrintSelf(ostream &os, vtkIndent indent)
clip any dataset with user-specified implicit function or input scalar data
Ray casting performed on the GPU.
static vtkGPUVolumeRayCastMapper * New()
virtual void PostRender(vtkRenderer *ren, int numberOfScalarComponents)=0
virtual void PreRender(vtkRenderer *ren, vtkVolume *vol, double datasetBounds[6], double scalarRange[2], int numberOfScalarComponents, unsigned int numberOfLevels)=0