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 =========================================================================*/
33 #ifndef vtkOpenGLGPUVolumeRayCastMapper_h
34 #define vtkOpenGLGPUVolumeRayCastMapper_h
35 
36 #include "vtkRenderingVolumeOpenGLModule.h" // For export macro
38 
39 class vtkVolume;
40 class vtkRenderer;
42 class vtkMatrix4x4;
43 class vtkUnsupportedRequiredExtensionsStringStream; // Pimpl
44 class vtkMapDataArrayTextureId; // Pimpl
45 class vtkMapMaskTextureId; // Pimpl
46 class vtkPolyData;
48 class vtkClipPolyData;
50 
51 class vtkOpacityTable; // internal class.
52 class vtkRGBTable; // internal class.
53 class vtkKWScalarField; // internal class.
54 class vtkKWMask; // internal class.
55 
56 class vtkOpacityTables; // Pimpl
57 class vtkDensifyPolyData;
58 class vtkStdString;
59 
60 class vtkShaderProgram2;
61 class vtkShader2;
62 
65 {
66 public:
69  virtual void PrintSelf(ostream& os, vtkIndent indent);
70 
72 
76  virtual int IsRenderSupported(vtkRenderWindow *window,
77  vtkVolumeProperty *property);
79 
81  virtual void ReleaseGraphicsResources(vtkWindow *window);
82 
85  static const char *OpenGLErrorMessage(unsigned int errorCode);
86 
89  static void PrintError(const char *headerMessage);
90 
91 protected:
94 
95  // The render method called by the superclass
96  virtual void GPURender(vtkRenderer *ren,
97  vtkVolume *vol);
98 
99  // Methods called by the AMR Volume Mapper.
100  virtual void PreRender(vtkRenderer *ren,
101  vtkVolume *vol,
102  double datasetBounds[6],
103  double scalarRange[2],
104  int numberOfScalarComponents,
105  unsigned int numberOfLevels);
106 
107  // \pre input is up-to-date
108  virtual void RenderBlock(vtkRenderer *ren,
109  vtkVolume *vol,
110  unsigned int level);
111 
112  virtual void PostRender(vtkRenderer *ren,
113  int numberOfScalarComponents);
114 
116 
120  int TestRequiredExtension(vtkOpenGLExtensionManager *extensions,
121  const char *extensionName);
123 
129  void LoadExtensions(vtkRenderWindow *window);
130 
136  void CreateOpenGLObjects(vtkRenderer *ren);
137 
143  int AllocateFrameBuffers(vtkRenderer *ren);
144 
146 
163  int LoadScalarField(vtkImageData *input,
164  vtkImageData *maskInput,
165  int textureExtent[6],
166  vtkVolume *volume);
168 
170 
174  int UpdateColorTransferFunction(vtkVolume *vol,
175  int numberOfScalarComponents);
177 
178 
182  int UpdateOpacityTransferFunction(vtkVolume *vol,
183  int numberOfScalarComponents,
184  unsigned int level);
186 
189  void SetupRender(vtkRenderer *ren, vtkVolume *vol);
190 
192 
194  void ClipBoundingBox(vtkRenderer *ren,
195  double worldBounds[6],
196  vtkVolume *vol);
198 
200 
203  int RenderClippedBoundingBox(int tcoordFlag,
204  size_t currentBlock,
205  size_t numberOfBlocks,
206  vtkRenderWindow *renWin);
208 
211  void CopyFBOToTexture();
212 
214  void CleanupRender();
215 
217  void RenderTextureToScreen(vtkRenderer *ren);
218 
221  int PowerOfTwoGreaterOrEqual(int x);
222 
224  void CheckFrameBufferStatus();
225 
228  vtkStdString BufferToString(int buffer);
229 
231  void DisplayReadAndDrawBuffers();
232 
234  void DisplayFrameBufferAttachments();
235 
237  void DisplayFrameBufferAttachment(unsigned int uattachment);
238 
240 
245  void BuildProgram(vtkRenderWindow *w,
246  int parallelProjection,
247  int raycastMethod,
248  int shadeMethod,
249  int componentMethod);
251 
253  void GetLightingStatus();
254 
264  void ComputeReductionFactor(double allocatedTime);
265 
267 
268  void RenderWholeVolume(vtkRenderer *ren,
269  vtkVolume *vol);
271 
273 
274  void RenderRegions(vtkRenderer *ren,
275  vtkVolume *vol);
277 
278  // Return abort status (true==abort)
279  int RenderSubVolume(vtkRenderer *ren,
280  double bounds[6],
281  vtkVolume *vol);
282 
283  void LoadProjectionParameters(vtkRenderer *ren,
284  vtkVolume *vol);
285 
287  void ComputeNumberOfCroppingRegions();
288 
289  void GetTextureFormat(vtkImageData *input,
290  unsigned int *internalFormat,
291  unsigned int *format,
292  unsigned int *type,
293  int *componentSize);
294 
295  bool TestLoadingScalar(unsigned int internalFormat,
296  unsigned int format,
297  unsigned int type,
298  int textureSize[3],
299  int componentSize);
300 
301  void SlabsFromDatasetToIndex(double slabsDataSet[6],
302  double slabsPoints[6]);
303 
304  void SlabsFromIndexToDataset(double slabsPoints[6],
305  double slabsDataSet[6]);
306 
307  const char *GetEnabledString(unsigned char value);
308  void GetOpenGLState();
309 
310  void DebugDisplayBox(vtkPolyData *box);
311 
312  void UpdateNoiseTexture();
313 
315 
319  double ComputeMinimalSampleDistancePerPixel(vtkRenderer *renderer,
320  vtkVolume *volume);
322 
331  virtual void GetReductionRatio(double ratio[3]);
332 
334 
335  // World coordinates of each corner of the dataset.
336  double BoundingBox[8][3];
337 
338  // Used during the clipping process.
342 
345 
347 
350 
351  unsigned int FrameBufferObject;
353 
354  // 3D scalar texture +1D color+1D opacity+2D grabbed depth buffer
355  // +1 2D colorbuffer.
356  unsigned int TextureObjects[5];
357  // used in MIP Mode (2 needed for ping-pong technique)
358  unsigned int MaxValueFrameBuffer;
359  unsigned int MaxValueFrameBuffer2;
360  int ReducedSize[2];
361 
363 
364  int LastSize[2];
365 
367 
368  // Supported extensions
369  // List of unsupported required extensions. Pimpl.
370  vtkUnsupportedRequiredExtensionsStringStream *UnsupportedRequiredExtensions;
372 
375 
377 
378  // Matrices used in internal computation. As a member variable,
379  // only one memory allocation is performed.
380  vtkMatrix4x4 *TempMatrix[3];
381 
382  double TableRange[2];
383 
384  // Final string to send to the GPU as the fragment program source code.
385 // char *FragmentCode;
386 // int FragmentCodeCapacity;
387 
390  char *ErrorString;
391 
392  // Store the last projection an raycast method in order to not rebuild
393  // the fragment code at every call.
399 
402 
405  void BuildScaleBiasProgram(vtkRenderWindow *w);
406 
407 #if 0
408  vtkIdType LoadedExtent[6];
409  double LoadedBounds[6];
410  vtkTimeStamp LoadedScalarTime;
411  int LoadedCellFlag; // point data or cell data (or field data, not handled) ?
412 #endif
413 
414  unsigned int SavedFrameBuffer; // some offscreen mode use a framebuffer too.
415 
417 
418  float *NoiseTexture;
419  int NoiseTextureSize; // size of one dimension.
420  unsigned int NoiseTextureId; // GLuint
421 
423 
424  vtkMapDataArrayTextureId *ScalarsTextures; // need a list for AMR mode.
425  vtkMapMaskTextureId *MaskTextures; // need a list for AMR mode.
426 
427  vtkRGBTable *RGBTable;
428  vtkRGBTable *Mask1RGBTable;
429  vtkRGBTable *Mask2RGBTable;
430 
431  vtkOpacityTables *OpacityTables;
432 
433  vtkKWScalarField *CurrentScalar;
434  vtkKWMask *CurrentMask;
435 
437 
438  double LastProgressEventTime; // initial value is 0.0. Expressed in seconds.
439 
441 
449 
450  // Internal Variable used to keep track of whether or render window's size
451  // changed and therefore we need re-allocation.
453 
455 
456 private:
458  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&); // Not implemented.
459 };
460 
461 #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
#define VTKRENDERINGVOLUMEOPENGL_EXPORT
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:63
int vtkIdType
Definition: vtkType.h:275
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:83
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