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 
63 class VTKRENDERINGVOLUMEOPENGL_EXPORT vtkOpenGLGPUVolumeRayCastMapper
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 
246  void BuildProgram(vtkRenderWindow *w,
247  int parallelProjection,
248  int raycastMethod,
249  int shadeMethod,
250  int componentMethod);
252 
254  void GetLightingStatus();
255 
265  void ComputeReductionFactor(double allocatedTime);
266 
268 
269  void RenderWholeVolume(vtkRenderer *ren,
270  vtkVolume *vol);
272 
274 
275  void RenderRegions(vtkRenderer *ren,
276  vtkVolume *vol);
278 
279  // Return abort status (true==abort)
280  int RenderSubVolume(vtkRenderer *ren,
281  double bounds[6],
282  vtkVolume *vol);
283 
284  void LoadProjectionParameters(vtkRenderer *ren,
285  vtkVolume *vol);
286 
288  void ComputeNumberOfCroppingRegions();
289 
290  void GetTextureFormat(vtkImageData *input,
291  unsigned int *internalFormat,
292  unsigned int *format,
293  unsigned int *type,
294  int *componentSize);
295 
296  bool TestLoadingScalar(unsigned int internalFormat,
297  unsigned int format,
298  unsigned int type,
299  int textureSize[3],
300  int componentSize);
301 
302  void SlabsFromDatasetToIndex(double slabsDataSet[6],
303  double slabsPoints[6]);
304 
305  void SlabsFromIndexToDataset(double slabsPoints[6],
306  double slabsDataSet[6]);
307 
308  const char *GetEnabledString(unsigned char value);
309  void GetOpenGLState();
310 
311  void DebugDisplayBox(vtkPolyData *box);
312 
313  void UpdateNoiseTexture();
314 
316 
320  double ComputeMinimalSampleDistancePerPixel(vtkRenderer *renderer,
321  vtkVolume *volume);
323 
332  virtual void GetReductionRatio(double ratio[3]);
333 
335 
336  // World coordinates of each corner of the dataset.
337  double BoundingBox[8][3];
338 
339  // Used during the clipping process.
343 
346 
348 
351 
352  unsigned int FrameBufferObject;
354 
355  // 3D scalar texture +1D color+1D opacity+2D grabbed depth buffer
356  // +1 2D colorbuffer.
357  unsigned int TextureObjects[5];
358  // used in MIP Mode (2 needed for ping-pong technique)
359  unsigned int MaxValueFrameBuffer;
360  unsigned int MaxValueFrameBuffer2;
361  int ReducedSize[2];
362 
364 
365  int LastSize[2];
366 
368 
369  // Supported extensions
370  // List of unsupported required extensions. Pimpl.
371  vtkUnsupportedRequiredExtensionsStringStream *UnsupportedRequiredExtensions;
373 
376 
378 
379  // Matrices used in internal computation. As a member variable,
380  // only one memory allocation is performed.
381  vtkMatrix4x4 *TempMatrix[3];
382 
383  double TableRange[2];
384 
385  // Final string to send to the GPU as the fragment program source code.
386 // char *FragmentCode;
387 // int FragmentCodeCapacity;
388 
391  char *ErrorString;
392 
393  // Store the last projection an raycast method in order to not rebuild
394  // the fragment code at every call.
400 
403 
406  void BuildScaleBiasProgram(vtkRenderWindow *w);
407 
408 #if 0
409  vtkIdType LoadedExtent[6];
410  double LoadedBounds[6];
411  vtkTimeStamp LoadedScalarTime;
412  int LoadedCellFlag; // point data or cell data (or field data, not handled) ?
413 #endif
414 
415  unsigned int SavedFrameBuffer; // some offscreen mode use a framebuffer too.
416 
418 
419  float *NoiseTexture;
420  int NoiseTextureSize; // size of one dimension.
421  unsigned int NoiseTextureId; // GLuint
422 
424 
425  vtkMapDataArrayTextureId *ScalarsTextures; // need a list for AMR mode.
426  vtkMapMaskTextureId *MaskTextures; // need a list for AMR mode.
427 
428  vtkRGBTable *RGBTable;
429  vtkRGBTable *Mask1RGBTable;
430  vtkRGBTable *Mask2RGBTable;
431 
432  vtkOpacityTables *OpacityTables;
433 
434  vtkKWScalarField *CurrentScalar;
435  vtkKWMask *CurrentMask;
436 
438 
439  double LastProgressEventTime; // initial value is 0.0. Expressed in seconds.
440 
442 
450 
451  // Internal Variable used to keep track of whether or render window's size
452  // changed and therefore we need re-allocation.
454 
456 
457 private:
459  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&); // Not implemented.
460 };
461 
462 #endif