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 
37 
38 class vtkVolume;
39 class vtkRenderer;
41 class vtkMatrix4x4;
42 class vtkUnsupportedRequiredExtensionsStringStream; // Pimpl
43 class vtkMapDataArrayTextureId; // Pimpl
44 class vtkMapMaskTextureId; // Pimpl
45 class vtkPolyData;
47 class vtkClipPolyData;
49 
50 class vtkOpacityTable; // internal class.
51 class vtkRGBTable; // internal class.
52 class vtkKWScalarField; // internal class.
53 class vtkKWMask; // internal class.
54 
55 class vtkOpacityTables; // Pimpl
56 class vtkDensifyPolyData;
57 class vtkStdString;
58 
59 class vtkShaderProgram2;
60 class vtkShader2;
61 
63 {
64 public:
67  virtual void PrintSelf(ostream& os, vtkIndent indent);
68 
70 
74  virtual int IsRenderSupported(vtkRenderWindow *window,
75  vtkVolumeProperty *property);
77 
79  virtual void ReleaseGraphicsResources(vtkWindow *window);
80 
83  static const char *OpenGLErrorMessage(unsigned int errorCode);
84 
87  static void PrintError(const char *headerMessage);
88 
89 protected:
92 
93  // The render method called by the superclass
94  virtual void GPURender(vtkRenderer *ren,
95  vtkVolume *vol);
96 
97  // Methods called by the AMR Volume Mapper.
98  virtual void PreRender(vtkRenderer *ren,
99  vtkVolume *vol,
100  double datasetBounds[6],
101  double scalarRange[2],
102  int numberOfScalarComponents,
103  unsigned int numberOfLevels);
104 
105  // \pre input is up-to-date
106  virtual void RenderBlock(vtkRenderer *ren,
107  vtkVolume *vol,
108  unsigned int level);
109 
110  virtual void PostRender(vtkRenderer *ren,
111  int numberOfScalarComponents);
112 
114 
118  int TestRequiredExtension(vtkOpenGLExtensionManager *extensions,
119  const char *extensionName);
121 
127  void LoadExtensions(vtkRenderWindow *window);
128 
134  void CreateOpenGLObjects(vtkRenderer *ren);
135 
141  int AllocateFrameBuffers(vtkRenderer *ren);
142 
144 
161  int LoadScalarField(vtkImageData *input,
162  vtkImageData *maskInput,
163  int textureExtent[6],
164  vtkVolume *volume);
166 
168 
172  int UpdateColorTransferFunction(vtkVolume *vol,
173  int numberOfScalarComponents);
175 
176 
180  int UpdateOpacityTransferFunction(vtkVolume *vol,
181  int numberOfScalarComponents,
182  unsigned int level);
184 
187  void SetupRender(vtkRenderer *ren, vtkVolume *vol);
188 
190 
192  void ClipBoundingBox(vtkRenderer *ren,
193  double worldBounds[6],
194  vtkVolume *vol);
196 
198 
201  int RenderClippedBoundingBox(int tcoordFlag,
202  size_t currentBlock,
203  size_t numberOfBlocks,
204  vtkRenderWindow *renWin);
206 
209  void CopyFBOToTexture();
210 
212  void CleanupRender();
213 
215  void RenderTextureToScreen(vtkRenderer *ren);
216 
219  int PowerOfTwoGreaterOrEqual(int x);
220 
222  void CheckFrameBufferStatus();
223 
226  vtkStdString BufferToString(int buffer);
227 
229  void DisplayReadAndDrawBuffers();
230 
232  void DisplayFrameBufferAttachments();
233 
235  void DisplayFrameBufferAttachment(unsigned int uattachment);
236 
238 
244  void BuildProgram(vtkRenderWindow *w,
245  int parallelProjection,
246  int raycastMethod,
247  int shadeMethod,
248  int componentMethod);
250 
252  void GetLightingStatus();
253 
263  void ComputeReductionFactor(double allocatedTime);
264 
266 
267  void RenderWholeVolume(vtkRenderer *ren,
268  vtkVolume *vol);
270 
272 
273  void RenderRegions(vtkRenderer *ren,
274  vtkVolume *vol);
276 
277  // Return abort status (true==abort)
278  int RenderSubVolume(vtkRenderer *ren,
279  double bounds[6],
280  vtkVolume *vol);
281 
282  void LoadProjectionParameters(vtkRenderer *ren,
283  vtkVolume *vol);
284 
286  void ComputeNumberOfCroppingRegions();
287 
288  void GetTextureFormat(vtkImageData *input,
289  unsigned int *internalFormat,
290  unsigned int *format,
291  unsigned int *type,
292  int *componentSize);
293 
294  bool TestLoadingScalar(unsigned int internalFormat,
295  unsigned int format,
296  unsigned int type,
297  int textureSize[3],
298  int componentSize);
299 
300  void SlabsFromDatasetToIndex(double slabsDataSet[6],
301  double slabsPoints[6]);
302 
303  void SlabsFromIndexToDataset(double slabsPoints[6],
304  double slabsDataSet[6]);
305 
306  const char *GetEnabledString(unsigned char value);
307  void GetOpenGLState();
308 
309  void DebugDisplayBox(vtkPolyData *box);
310 
311  void UpdateNoiseTexture();
312 
314 
318  double ComputeMinimalSampleDistancePerPixel(vtkRenderer *renderer,
319  vtkVolume *volume);
321 
330  virtual void GetReductionRatio(double ratio[3]);
331 
333 
334  // World coordinates of each corner of the dataset.
335  double BoundingBox[8][3];
336 
337  // Used during the clipping process.
341 
344 
346 
349 
350  unsigned int FrameBufferObject;
352 
353  // 3D scalar texture +1D color+1D opacity+2D grabbed depth buffer
354  // +1 2D colorbuffer.
355  unsigned int TextureObjects[5];
356  // used in MIP Mode (2 needed for ping-pong technique)
357  unsigned int MaxValueFrameBuffer;
358  unsigned int MaxValueFrameBuffer2;
359  int ReducedSize[2];
360 
362 
363  int LastSize[2];
364 
366 
367  // Supported extensions
368  // List of unsupported required extensions. Pimpl.
369  vtkUnsupportedRequiredExtensionsStringStream *UnsupportedRequiredExtensions;
371 
374 
376 
377  // Matrices used in internal computation. As a member variable,
378  // only one memory allocation is performed.
379  vtkMatrix4x4 *TempMatrix[3];
380 
381  double TableRange[2];
382 
383  // Final string to send to the GPU as the fragment program source code.
384 // char *FragmentCode;
385 // int FragmentCodeCapacity;
386 
389  char *ErrorString;
390 
391  // Store the last projection an raycast method in order to not rebuild
392  // the fragment code at every call.
398 
401 
404  void BuildScaleBiasProgram(vtkRenderWindow *w);
405 
406 #if 0
407  vtkIdType LoadedExtent[6];
408  double LoadedBounds[6];
409  vtkTimeStamp LoadedScalarTime;
410  int LoadedCellFlag; // point data or cell data (or field data, not handled) ?
411 #endif
412 
413  unsigned int SavedFrameBuffer; // some offscreen mode use a framebuffer too.
414 
416 
417  float *NoiseTexture;
418  int NoiseTextureSize; // size of one dimension.
419  unsigned int NoiseTextureId; // GLuint
420 
422 
423  vtkMapDataArrayTextureId *ScalarsTextures; // need a list for AMR mode.
424  vtkMapMaskTextureId *MaskTextures; // need a list for AMR mode.
425 
426  vtkRGBTable *RGBTable;
427  vtkRGBTable *Mask1RGBTable;
428  vtkRGBTable *Mask2RGBTable;
429 
430  vtkOpacityTables *OpacityTables;
431 
432  vtkKWScalarField *CurrentScalar;
433  vtkKWMask *CurrentMask;
434 
436 
437  double LastProgressEventTime; // initial value is 0.0. Expressed in seconds.
438 
440 
448 
449  // Internal Variable used to keep track of whether or render window's size
450  // changed and therefore we need re-allocation.
452 
454 
455 private:
457  void operator=(const vtkOpenGLGPUVolumeRayCastMapper&); // Not implemented.
458 };
459 
460 #endif