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 =========================================================================*/
29 #ifndef __vtkOpenGLGPUVolumeRayCastMapper_h
30 #define __vtkOpenGLGPUVolumeRayCastMapper_h
31 
33 
34 class vtkVolume;
35 class vtkRenderer;
37 class vtkMatrix4x4;
38 class vtkUnsupportedRequiredExtensionsStringStream; // Pimpl
39 class vtkMapDataArrayTextureId; // Pimpl
40 class vtkMapMaskTextureId; // Pimpl
41 class vtkPolyData;
43 class vtkClipPolyData;
45 
46 class vtkOpacityTable; // internal class.
47 class vtkRGBTable; // internal class.
48 class vtkKWScalarField; // internal class.
49 class vtkKWMask; // internal class.
50 
51 class vtkOpacityTables; // Pimpl
52 class vtkDensifyPolyData;
53 class vtkStdString;
54 
55 class vtkShaderProgram2;
56 class vtkShader2;
57 
59 {
60 public:
63  virtual void PrintSelf(ostream& os, vtkIndent indent);
64 
66 
70  virtual int IsRenderSupported(vtkRenderWindow *window,
71  vtkVolumeProperty *property);
73 
75  virtual void ReleaseGraphicsResources(vtkWindow *window);
76 
79  static const char *OpenGLErrorMessage(unsigned int errorCode);
80 
83  static void PrintError(const char *headerMessage);
84 
85 protected:
88 
89  // The render method called by the superclass
90  virtual void GPURender(vtkRenderer *ren,
91  vtkVolume *vol);
92 
93  // Methods called by the AMR Volume Mapper.
94  virtual void PreRender(vtkRenderer *ren,
95  vtkVolume *vol,
96  double datasetBounds[6],
97  double scalarRange[2],
98  int numberOfScalarComponents,
99  unsigned int numberOfLevels);
100 
101  // \pre input is up-to-date
102  virtual void RenderBlock(vtkRenderer *ren,
103  vtkVolume *vol,
104  unsigned int level);
105 
106  virtual void PostRender(vtkRenderer *ren,
107  int numberOfScalarComponents);
108 
110 
114  int TestRequiredExtension(vtkOpenGLExtensionManager *extensions,
115  const char *extensionName);
117 
123  void LoadExtensions(vtkRenderWindow *window);
124 
130  void CreateOpenGLObjects(vtkRenderer *ren);
131 
137  int AllocateFrameBuffers(vtkRenderer *ren);
138 
140 
157  int LoadScalarField(vtkImageData *input,
158  vtkImageData *maskInput,
159  int textureExtent[6],
160  vtkVolume *volume);
162 
164 
168  int UpdateColorTransferFunction(vtkVolume *vol,
169  int numberOfScalarComponents);
170  // Description:
171  // Allocate memory and load opacity table on the GPU or
172  // reload it if the transfer functions changed.
173  // \pre vol_exists: vol!=0
174  // \pre valid_numberOfScalarComponents: numberOfScalarComponents==1 || numberOfScalarComponents==4
175  int UpdateOpacityTransferFunction(vtkVolume *vol,
176  int numberOfScalarComponents,
177  unsigned int level);
179 
182  void SetupRender(vtkRenderer *ren, vtkVolume *vol);
183 
185 
187  void ClipBoundingBox(vtkRenderer *ren,
188  double worldBounds[6],
189  vtkVolume *vol);
191 
193 
196  int RenderClippedBoundingBox(int tcoordFlag,
197  size_t currentBlock,
198  size_t numberOfBlocks,
199  vtkRenderWindow *renWin);
201 
204  void CopyFBOToTexture();
205 
207  void CleanupRender();
208 
210  void RenderTextureToScreen(vtkRenderer *ren);
211 
214  int PowerOfTwoGreaterOrEqual(int x);
215 
217  void CheckFrameBufferStatus();
218 
221  vtkStdString BufferToString(int buffer);
222 
224  void DisplayReadAndDrawBuffers();
225 
227  void DisplayFrameBufferAttachments();
228 
230  void DisplayFrameBufferAttachment(unsigned int uattachment);
231 
233 
239  void BuildProgram(vtkRenderWindow *w,
240  int parallelProjection,
241  int raycastMethod,
242  int shadeMethod,
243  int componentMethod);
245 
247  void GetLightingStatus();
248 
258  void ComputeReductionFactor(double allocatedTime);
259 
261 
262  void RenderWholeVolume(vtkRenderer *ren,
263  vtkVolume *vol);
265 
267 
268  void RenderRegions(vtkRenderer *ren,
269  vtkVolume *vol);
271 
272  // Return abort status (true==abort)
273  int RenderSubVolume(vtkRenderer *ren,
274  double bounds[6],
275  vtkVolume *vol);
276 
277  void LoadProjectionParameters(vtkRenderer *ren,
278  vtkVolume *vol);
279 
281  void ComputeNumberOfCroppingRegions();
282 
283  void GetTextureFormat(vtkImageData *input,
284  unsigned int *internalFormat,
285  unsigned int *format,
286  unsigned int *type,
287  int *componentSize);
288 
289  bool TestLoadingScalar(unsigned int internalFormat,
290  unsigned int format,
291  unsigned int type,
292  int textureSize[3],
293  int componentSize);
294 
295  void SlabsFromDatasetToIndex(double slabsDataSet[6],
296  double slabsPoints[6]);
297 
298  void SlabsFromIndexToDataset(double slabsPoints[6],
299  double slabsDataSet[6]);
300 
301  const char *GetEnabledString(unsigned char value);
302  void GetOpenGLState();
303 
304  void DebugDisplayBox(vtkPolyData *box);
305 
306  void UpdateNoiseTexture();
307 
309 
313  double ComputeMinimalSampleDistancePerPixel(vtkRenderer *renderer,
314  vtkVolume *volume);
316 
325  virtual void GetReductionRatio(double ratio[3]);
326 
328 
329  // World coordinates of each corner of the dataset.
330  double BoundingBox[8][3];
331 
332  // Used during the clipping process.
336 
339 
341 
344 
345  unsigned int FrameBufferObject;
347 
348  // 3D scalar texture +1D color+1D opacity+2D grabbed depth buffer
349  // +1 2D colorbuffer.
350  unsigned int TextureObjects[5];
351  // used in MIP Mode (2 needed for ping-pong technique)
352  unsigned int MaxValueFrameBuffer;
353  unsigned int MaxValueFrameBuffer2;
354  int ReducedSize[2];
355 
357 
358  int LastSize[2];
359 
361 
362  // Supported extensions
363  // List of unsupported required extensions. Pimpl.
364  vtkUnsupportedRequiredExtensionsStringStream *UnsupportedRequiredExtensions;
366 
369 
371 
372  // Matrices used in internal computation. As a member variable,
373  // only one memory allocation is performed.
374  vtkMatrix4x4 *TempMatrix[3];
375 
376  double TableRange[2];
377 
378  // Final string to send to the GPU as the fragment program source code.
379 // char *FragmentCode;
380 // int FragmentCodeCapacity;
381 
384  char *ErrorString;
385 
386  // Store the last projection an raycast method in order to not rebuild
387  // the fragment code at every call.
393 
396 
399  void BuildScaleBiasProgram(vtkRenderWindow *w);
400 
401 #if 0
402  vtkIdType LoadedExtent[6];
403  double LoadedBounds[6];
404  vtkTimeStamp LoadedScalarTime;
405  int LoadedCellFlag; // point data or cell data (or field data, not handled) ?
406 #endif
407 
408  unsigned int SavedFrameBuffer; // some offscreen mode use a framebuffer too.
409 
411 
412  float *NoiseTexture;
413  int NoiseTextureSize; // size of one dimension.
414  unsigned int NoiseTextureId; // GLuint
415 
417 
418  vtkMapDataArrayTextureId *ScalarsTextures; // need a list for AMR mode.
419  vtkMapMaskTextureId *MaskTextures; // need a list for AMR mode.
420 
421  vtkRGBTable *RGBTable;
422  vtkRGBTable *Mask1RGBTable;
423  vtkRGBTable *Mask2RGBTable;
424 
425  vtkOpacityTables *OpacityTables;
426 
427  vtkKWScalarField *CurrentScalar;
428  vtkKWMask *CurrentMask;
429 
431 
432  double LastProgressEventTime; // initial value is 0.0. Expressed in seconds.
433 
435 
443 
444  // Internal Variable used to keep track of whether or render window's size
445  // changed and therefore we need re-allocation.
447 
449 
450 private:
452  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&); // Not implemented.
453 };
454 
455 #endif