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 =========================================================================*/
37 #ifndef vtkOpenGLGPUVolumeRayCastMapper_h
38 #define vtkOpenGLGPUVolumeRayCastMapper_h
39 
40 #include "vtkRenderingVolumeOpenGLModule.h" // For export macro
42 
43 class vtkVolume;
44 class vtkRenderer;
46 class vtkMatrix4x4;
47 class vtkUnsupportedRequiredExtensionsStringStream; // Pimpl
48 class vtkMapDataArrayTextureId; // Pimpl
49 class vtkMapMaskTextureId; // Pimpl
50 class vtkPolyData;
52 class vtkClipPolyData;
54 
55 class vtkOpacityTable; // internal class.
56 class vtkRGBTable; // internal class.
57 class vtkKWScalarField; // internal class.
58 class vtkKWMask; // internal class.
59 
60 class vtkOpacityTables; // Pimpl
61 class vtkDensifyPolyData;
62 class vtkStdString;
63 
64 class vtkShaderProgram2;
65 class vtkShader2;
66 
67 class VTKRENDERINGVOLUMEOPENGL_EXPORT vtkOpenGLGPUVolumeRayCastMapper
69 {
70 public:
73  void PrintSelf(ostream& os, vtkIndent indent) override;
74 
82  vtkVolumeProperty *property) override;
83 
88  void ReleaseGraphicsResources(vtkWindow *window) override;
89 
94  static const char *OpenGLErrorMessage(unsigned int errorCode);
95 
101  static void PrintError(const char *headerMessage);
102 
103 protected:
106 
107  // The render method called by the superclass
108  void GPURender(vtkRenderer *ren,
109  vtkVolume *vol) override;
110 
111  // Methods called by the AMR Volume Mapper.
112  void PreRender(vtkRenderer *ren,
113  vtkVolume *vol,
114  double datasetBounds[6],
115  double scalarRange[2],
116  int numberOfScalarComponents,
117  unsigned int numberOfLevels) override;
118 
119  // \pre input is up-to-date
120  void RenderBlock(vtkRenderer *ren,
121  vtkVolume *vol,
122  unsigned int level) override;
123 
124  void PostRender(vtkRenderer *ren,
125  int numberOfScalarComponents) override;
126 
134  int TestRequiredExtension(vtkOpenGLExtensionManager *extensions,
135  const char *extensionName);
136 
144  void LoadExtensions(vtkRenderWindow *window);
145 
153  void CreateOpenGLObjects(vtkRenderer *ren);
154 
163  int AllocateFrameBuffers(vtkRenderer *ren);
164 
187  int LoadScalarField(vtkImageData *input,
188  vtkImageData *maskInput,
189  int textureExtent[6],
190  vtkVolume *volume);
191 
198  int UpdateColorTransferFunction(vtkVolume *vol,
199  int numberOfScalarComponents);
206  int UpdateOpacityTransferFunction(vtkVolume *vol,
207  int numberOfScalarComponents,
208  unsigned int level);
209 
215  void SetupRender(vtkRenderer *ren, vtkVolume *vol);
216 
221  void ClipBoundingBox(vtkRenderer *ren,
222  double worldBounds[6],
223  vtkVolume *vol);
224 
230  int RenderClippedBoundingBox(int tcoordFlag,
231  size_t currentBlock,
232  size_t numberOfBlocks,
233  vtkRenderWindow *renWin);
234 
239  void CopyFBOToTexture();
240 
244  void CleanupRender();
245 
250  void RenderTextureToScreen(vtkRenderer *ren);
251 
257  int PowerOfTwoGreaterOrEqual(int x);
258 
262  void CheckFrameBufferStatus();
263 
267  vtkStdString BufferToString(int buffer);
268 
272  void DisplayReadAndDrawBuffers();
273 
277  void DisplayFrameBufferAttachments();
278 
282  void DisplayFrameBufferAttachment(unsigned int uattachment);
283 
289  void BuildProgram(vtkRenderWindow *w,
290  int parallelProjection,
291  int raycastMethod,
292  int shadeMethod,
293  int componentMethod);
294 
298  void GetLightingStatus();
299 
310  void ComputeReductionFactor(double allocatedTime);
311 
316  void RenderWholeVolume(vtkRenderer *ren,
317  vtkVolume *vol);
318 
323  void RenderRegions(vtkRenderer *ren,
324  vtkVolume *vol);
325 
326  // Return abort status (true==abort)
327  int RenderSubVolume(vtkRenderer *ren,
328  double bounds[6],
329  vtkVolume *vol);
330 
331  void LoadProjectionParameters(vtkRenderer *ren,
332  vtkVolume *vol);
333 
337  void ComputeNumberOfCroppingRegions();
338 
339  void GetTextureFormat(vtkImageData *input,
340  unsigned int *internalFormat,
341  unsigned int *format,
342  unsigned int *type,
343  int *componentSize);
344 
345  bool TestLoadingScalar(unsigned int internalFormat,
346  unsigned int format,
347  unsigned int type,
348  int textureSize[3],
349  int componentSize);
350 
351  void SlabsFromDatasetToIndex(double slabsDataSet[6],
352  double slabsPoints[6]);
353 
354  void SlabsFromIndexToDataset(double slabsPoints[6],
355  double slabsDataSet[6]);
356 
357  const char *GetEnabledString(unsigned char value);
358  void GetOpenGLState();
359 
360  void DebugDisplayBox(vtkPolyData *box);
361 
362  void UpdateNoiseTexture();
363 
370  double ComputeMinimalSampleDistancePerPixel(vtkRenderer *renderer,
371  vtkVolume *volume);
372 
385  void GetReductionRatio(double ratio[3]) override;
386 
388 
389  // World coordinates of each corner of the dataset.
390  double BoundingBox[8][3];
391 
392  // Used during the clipping process.
396 
399 
401 
404 
405  unsigned int FrameBufferObject;
407 
408  // 3D scalar texture +1D color+1D opacity+2D grabbed depth buffer
409  // +1 2D colorbuffer.
410  unsigned int TextureObjects[5];
411  // used in MIP Mode (2 needed for ping-pong technique)
412  unsigned int MaxValueFrameBuffer;
413  unsigned int MaxValueFrameBuffer2;
414  int ReducedSize[2];
415 
417 
418  int LastSize[2];
419 
421 
422  // Supported extensions
423  // List of unsupported required extensions. Pimpl.
424  vtkUnsupportedRequiredExtensionsStringStream *UnsupportedRequiredExtensions;
426 
429 
431 
432  // Matrices used in internal computation. As a member variable,
433  // only one memory allocation is performed.
434  vtkMatrix4x4 *TempMatrix[3];
435 
436  double TableRange[2];
437 
438  // Final string to send to the GPU as the fragment program source code.
439 // char *FragmentCode;
440 // int FragmentCodeCapacity;
441 
444  char *ErrorString;
445 
446  // Store the last projection an raycast method in order to not rebuild
447  // the fragment code at every call.
453 
456 
461  void BuildScaleBiasProgram(vtkRenderWindow *w);
462 
463 #if 0
464  vtkIdType LoadedExtent[6];
465  double LoadedBounds[6];
466  vtkTimeStamp LoadedScalarTime;
467  int LoadedCellFlag; // point data or cell data (or field data, not handled) ?
468 #endif
469 
470  unsigned int SavedFrameBuffer; // some offscreen mode use a framebuffer too.
471 
473 
474  float *NoiseTexture;
475  int NoiseTextureSize; // size of one dimension.
476  unsigned int NoiseTextureId; // GLuint
477 
479 
480  vtkMapDataArrayTextureId *ScalarsTextures; // need a list for AMR mode.
481  vtkMapMaskTextureId *MaskTextures; // need a list for AMR mode.
482 
483  vtkRGBTable *RGBTable;
484  vtkRGBTable *Mask1RGBTable;
485  vtkRGBTable *Mask2RGBTable;
486 
487  vtkOpacityTables *OpacityTables;
488 
489  vtkKWScalarField *CurrentScalar;
490  vtkKWMask *CurrentMask;
491 
493 
494  double LastProgressEventTime; // initial value is 0.0. Expressed in seconds.
495 
497 
505 
506  // Internal Variable used to keep track of whether or render window's size
507  // changed and therefore we need re-allocation.
509 
511 
512 private:
514  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&) = delete;
515 };
516 
517 #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:40
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
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:345
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.
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.
clip any dataset with user-specified implicit function or input scalar data
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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