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 =========================================================================*/
31 #ifndef vtkOpenGLGPUVolumeRayCastMapper_h
32 #define vtkOpenGLGPUVolumeRayCastMapper_h
33 
34 #include "vtkRenderingVolumeOpenGLModule.h" // For export macro
36 
37 class vtkVolume;
38 class vtkRenderer;
40 class vtkMatrix4x4;
41 class vtkUnsupportedRequiredExtensionsStringStream; // Pimpl
42 class vtkMapDataArrayTextureId; // Pimpl
43 class vtkMapMaskTextureId; // Pimpl
44 class vtkPolyData;
46 class vtkClipPolyData;
48 
49 class vtkOpacityTable; // internal class.
50 class vtkRGBTable; // internal class.
51 class vtkKWScalarField; // internal class.
52 class vtkKWMask; // internal class.
53 
54 class vtkOpacityTables; // Pimpl
55 class vtkDensifyPolyData;
56 class vtkStdString;
57 
58 class vtkShaderProgram2;
59 class vtkShader2;
60 
61 class VTKRENDERINGVOLUMEOPENGL_EXPORT vtkOpenGLGPUVolumeRayCastMapper
63 {
64 public:
67  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
68 
75  virtual int IsRenderSupported(vtkRenderWindow *window,
76  vtkVolumeProperty *property);
77 
82  virtual void ReleaseGraphicsResources(vtkWindow *window);
83 
88  static const char *OpenGLErrorMessage(unsigned int errorCode);
89 
95  static void PrintError(const char *headerMessage);
96 
97 protected:
100 
101  // The render method called by the superclass
102  virtual void GPURender(vtkRenderer *ren,
103  vtkVolume *vol);
104 
105  // Methods called by the AMR Volume Mapper.
106  virtual void PreRender(vtkRenderer *ren,
107  vtkVolume *vol,
108  double datasetBounds[6],
109  double scalarRange[2],
110  int numberOfScalarComponents,
111  unsigned int numberOfLevels);
112 
113  // \pre input is up-to-date
114  virtual void RenderBlock(vtkRenderer *ren,
115  vtkVolume *vol,
116  unsigned int level);
117 
118  virtual void PostRender(vtkRenderer *ren,
119  int numberOfScalarComponents);
120 
128  int TestRequiredExtension(vtkOpenGLExtensionManager *extensions,
129  const char *extensionName);
130 
138  void LoadExtensions(vtkRenderWindow *window);
139 
147  void CreateOpenGLObjects(vtkRenderer *ren);
148 
157  int AllocateFrameBuffers(vtkRenderer *ren);
158 
181  int LoadScalarField(vtkImageData *input,
182  vtkImageData *maskInput,
183  int textureExtent[6],
184  vtkVolume *volume);
185 
192  int UpdateColorTransferFunction(vtkVolume *vol,
193  int numberOfScalarComponents);
200  int UpdateOpacityTransferFunction(vtkVolume *vol,
201  int numberOfScalarComponents,
202  unsigned int level);
203 
209  void SetupRender(vtkRenderer *ren, vtkVolume *vol);
210 
215  void ClipBoundingBox(vtkRenderer *ren,
216  double worldBounds[6],
217  vtkVolume *vol);
218 
224  int RenderClippedBoundingBox(int tcoordFlag,
225  size_t currentBlock,
226  size_t numberOfBlocks,
227  vtkRenderWindow *renWin);
228 
233  void CopyFBOToTexture();
234 
238  void CleanupRender();
239 
244  void RenderTextureToScreen(vtkRenderer *ren);
245 
251  int PowerOfTwoGreaterOrEqual(int x);
252 
256  void CheckFrameBufferStatus();
257 
261  vtkStdString BufferToString(int buffer);
262 
266  void DisplayReadAndDrawBuffers();
267 
271  void DisplayFrameBufferAttachments();
272 
276  void DisplayFrameBufferAttachment(unsigned int uattachment);
277 
283  void BuildProgram(vtkRenderWindow *w,
284  int parallelProjection,
285  int raycastMethod,
286  int shadeMethod,
287  int componentMethod);
288 
292  void GetLightingStatus();
293 
304  void ComputeReductionFactor(double allocatedTime);
305 
310  void RenderWholeVolume(vtkRenderer *ren,
311  vtkVolume *vol);
312 
317  void RenderRegions(vtkRenderer *ren,
318  vtkVolume *vol);
319 
320  // Return abort status (true==abort)
321  int RenderSubVolume(vtkRenderer *ren,
322  double bounds[6],
323  vtkVolume *vol);
324 
325  void LoadProjectionParameters(vtkRenderer *ren,
326  vtkVolume *vol);
327 
331  void ComputeNumberOfCroppingRegions();
332 
333  void GetTextureFormat(vtkImageData *input,
334  unsigned int *internalFormat,
335  unsigned int *format,
336  unsigned int *type,
337  int *componentSize);
338 
339  bool TestLoadingScalar(unsigned int internalFormat,
340  unsigned int format,
341  unsigned int type,
342  int textureSize[3],
343  int componentSize);
344 
345  void SlabsFromDatasetToIndex(double slabsDataSet[6],
346  double slabsPoints[6]);
347 
348  void SlabsFromIndexToDataset(double slabsPoints[6],
349  double slabsDataSet[6]);
350 
351  const char *GetEnabledString(unsigned char value);
352  void GetOpenGLState();
353 
354  void DebugDisplayBox(vtkPolyData *box);
355 
356  void UpdateNoiseTexture();
357 
364  double ComputeMinimalSampleDistancePerPixel(vtkRenderer *renderer,
365  vtkVolume *volume);
366 
379  virtual void GetReductionRatio(double ratio[3]);
380 
382 
383  // World coordinates of each corner of the dataset.
384  double BoundingBox[8][3];
385 
386  // Used during the clipping process.
390 
393 
395 
398 
399  unsigned int FrameBufferObject;
401 
402  // 3D scalar texture +1D color+1D opacity+2D grabbed depth buffer
403  // +1 2D colorbuffer.
404  unsigned int TextureObjects[5];
405  // used in MIP Mode (2 needed for ping-pong technique)
406  unsigned int MaxValueFrameBuffer;
407  unsigned int MaxValueFrameBuffer2;
408  int ReducedSize[2];
409 
411 
412  int LastSize[2];
413 
415 
416  // Supported extensions
417  // List of unsupported required extensions. Pimpl.
418  vtkUnsupportedRequiredExtensionsStringStream *UnsupportedRequiredExtensions;
420 
423 
425 
426  // Matrices used in internal computation. As a member variable,
427  // only one memory allocation is performed.
428  vtkMatrix4x4 *TempMatrix[3];
429 
430  double TableRange[2];
431 
432  // Final string to send to the GPU as the fragment program source code.
433 // char *FragmentCode;
434 // int FragmentCodeCapacity;
435 
438  char *ErrorString;
439 
440  // Store the last projection an raycast method in order to not rebuild
441  // the fragment code at every call.
447 
450 
455  void BuildScaleBiasProgram(vtkRenderWindow *w);
456 
457 #if 0
458  vtkIdType LoadedExtent[6];
459  double LoadedBounds[6];
460  vtkTimeStamp LoadedScalarTime;
461  int LoadedCellFlag; // point data or cell data (or field data, not handled) ?
462 #endif
463 
464  unsigned int SavedFrameBuffer; // some offscreen mode use a framebuffer too.
465 
467 
468  float *NoiseTexture;
469  int NoiseTextureSize; // size of one dimension.
470  unsigned int NoiseTextureId; // GLuint
471 
473 
474  vtkMapDataArrayTextureId *ScalarsTextures; // need a list for AMR mode.
475  vtkMapMaskTextureId *MaskTextures; // need a list for AMR mode.
476 
477  vtkRGBTable *RGBTable;
478  vtkRGBTable *Mask1RGBTable;
479  vtkRGBTable *Mask2RGBTable;
480 
481  vtkOpacityTables *OpacityTables;
482 
483  vtkKWScalarField *CurrentScalar;
484  vtkKWMask *CurrentMask;
485 
487 
488  double LastProgressEventTime; // initial value is 0.0. Expressed in seconds.
489 
491 
499 
500  // Internal Variable used to keep track of whether or render window's size
501  // changed and therefore we need re-allocation.
503 
505 
506 private:
508  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) VTK_DELETE_FUNCTION;
509 };
510 
511 #endif
GLSL Shader.
Definition: vtkShader2.h:62
virtual void GPURender(vtkRenderer *, vtkVolume *)
Handled in the subclass - the actual render method.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:47
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:50
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
record modification and/or execution time
Definition: vtkTimeStamp.h:35
maintain a list of planes
abstract specification for renderers
Definition: vtkRenderer.h:63
int vtkIdType
Definition: vtkType.h:287
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
vtkUnsupportedRequiredExtensionsStringStream * UnsupportedRequiredExtensions
OpenGL subclass that draws the image to the screen.
GLSL Program.
a simple class to control print indentation
Definition: vtkIndent.h:39
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
perform various plane computations
Definition: vtkPlane.h:37
virtual void GetReductionRatio(double ratio[3])=0
Return how much the dataset has to be reduced in each dimension to fit on the GPU.
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))
Based on hardware and properties, we may or may not be able to render using 3D texture mapping...
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)
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.
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