VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkOpenGLGPUVolumeRayCastMapper.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00033 #ifndef __vtkOpenGLGPUVolumeRayCastMapper_h 00034 #define __vtkOpenGLGPUVolumeRayCastMapper_h 00035 00036 #include "vtkRenderingVolumeOpenGLModule.h" // For export macro 00037 #include "vtkGPUVolumeRayCastMapper.h" 00038 00039 class vtkVolume; 00040 class vtkRenderer; 00041 class vtkOpenGLExtensionManager; 00042 class vtkMatrix4x4; 00043 class vtkUnsupportedRequiredExtensionsStringStream; // Pimpl 00044 class vtkMapDataArrayTextureId; // Pimpl 00045 class vtkMapMaskTextureId; // Pimpl 00046 class vtkPolyData; 00047 class vtkClipConvexPolyData; 00048 class vtkClipPolyData; 00049 class vtkTessellatedBoxSource; 00050 00051 class vtkOpacityTable; // internal class. 00052 class vtkRGBTable; // internal class. 00053 class vtkKWScalarField; // internal class. 00054 class vtkKWMask; // internal class. 00055 00056 class vtkOpacityTables; // Pimpl 00057 class vtkDensifyPolyData; 00058 class vtkStdString; 00059 00060 class vtkShaderProgram2; 00061 class vtkShader2; 00062 00063 class VTKRENDERINGVOLUMEOPENGL_EXPORT vtkOpenGLGPUVolumeRayCastMapper 00064 : public vtkGPUVolumeRayCastMapper 00065 { 00066 public: 00067 static vtkOpenGLGPUVolumeRayCastMapper *New(); 00068 vtkTypeMacro(vtkOpenGLGPUVolumeRayCastMapper,vtkGPUVolumeRayCastMapper); 00069 virtual void PrintSelf(ostream& os, vtkIndent indent); 00070 00072 00076 virtual int IsRenderSupported(vtkRenderWindow *window, 00077 vtkVolumeProperty *property); 00079 00081 virtual void ReleaseGraphicsResources(vtkWindow *window); 00082 00085 static const char *OpenGLErrorMessage(unsigned int errorCode); 00086 00089 static void PrintError(const char *headerMessage); 00090 00091 protected: 00092 vtkOpenGLGPUVolumeRayCastMapper(); 00093 ~vtkOpenGLGPUVolumeRayCastMapper(); 00094 00095 // The render method called by the superclass 00096 virtual void GPURender(vtkRenderer *ren, 00097 vtkVolume *vol); 00098 00099 // Methods called by the AMR Volume Mapper. 00100 virtual void PreRender(vtkRenderer *ren, 00101 vtkVolume *vol, 00102 double datasetBounds[6], 00103 double scalarRange[2], 00104 int numberOfScalarComponents, 00105 unsigned int numberOfLevels); 00106 00107 // \pre input is up-to-date 00108 virtual void RenderBlock(vtkRenderer *ren, 00109 vtkVolume *vol, 00110 unsigned int level); 00111 00112 virtual void PostRender(vtkRenderer *ren, 00113 int numberOfScalarComponents); 00114 00116 00120 int TestRequiredExtension(vtkOpenGLExtensionManager *extensions, 00121 const char *extensionName); 00123 00129 void LoadExtensions(vtkRenderWindow *window); 00130 00136 void CreateOpenGLObjects(vtkRenderer *ren); 00137 00143 int AllocateFrameBuffers(vtkRenderer *ren); 00144 00146 00163 int LoadScalarField(vtkImageData *input, 00164 vtkImageData *maskInput, 00165 int textureExtent[6], 00166 vtkVolume *volume); 00168 00170 00174 int UpdateColorTransferFunction(vtkVolume *vol, 00175 int numberOfScalarComponents); 00177 00178 00182 int UpdateOpacityTransferFunction(vtkVolume *vol, 00183 int numberOfScalarComponents, 00184 unsigned int level); 00186 00189 void SetupRender(vtkRenderer *ren, vtkVolume *vol); 00190 00192 00194 void ClipBoundingBox(vtkRenderer *ren, 00195 double worldBounds[6], 00196 vtkVolume *vol); 00198 00200 00203 int RenderClippedBoundingBox(int tcoordFlag, 00204 size_t currentBlock, 00205 size_t numberOfBlocks, 00206 vtkRenderWindow *renWin); 00208 00211 void CopyFBOToTexture(); 00212 00214 void CleanupRender(); 00215 00217 void RenderTextureToScreen(vtkRenderer *ren); 00218 00221 int PowerOfTwoGreaterOrEqual(int x); 00222 00224 void CheckFrameBufferStatus(); 00225 00228 vtkStdString BufferToString(int buffer); 00229 00231 void DisplayReadAndDrawBuffers(); 00232 00234 void DisplayFrameBufferAttachments(); 00235 00237 void DisplayFrameBufferAttachment(unsigned int uattachment); 00238 00240 00246 void BuildProgram(vtkRenderWindow *w, 00247 int parallelProjection, 00248 int raycastMethod, 00249 int shadeMethod, 00250 int componentMethod); 00252 00254 void GetLightingStatus(); 00255 00265 void ComputeReductionFactor(double allocatedTime); 00266 00268 00269 void RenderWholeVolume(vtkRenderer *ren, 00270 vtkVolume *vol); 00272 00274 00275 void RenderRegions(vtkRenderer *ren, 00276 vtkVolume *vol); 00278 00279 // Return abort status (true==abort) 00280 int RenderSubVolume(vtkRenderer *ren, 00281 double bounds[6], 00282 vtkVolume *vol); 00283 00284 void LoadProjectionParameters(vtkRenderer *ren, 00285 vtkVolume *vol); 00286 00288 void ComputeNumberOfCroppingRegions(); 00289 00290 void GetTextureFormat(vtkImageData *input, 00291 unsigned int *internalFormat, 00292 unsigned int *format, 00293 unsigned int *type, 00294 int *componentSize); 00295 00296 bool TestLoadingScalar(unsigned int internalFormat, 00297 unsigned int format, 00298 unsigned int type, 00299 int textureSize[3], 00300 int componentSize); 00301 00302 void SlabsFromDatasetToIndex(double slabsDataSet[6], 00303 double slabsPoints[6]); 00304 00305 void SlabsFromIndexToDataset(double slabsPoints[6], 00306 double slabsDataSet[6]); 00307 00308 const char *GetEnabledString(unsigned char value); 00309 void GetOpenGLState(); 00310 00311 void DebugDisplayBox(vtkPolyData *box); 00312 00313 void UpdateNoiseTexture(); 00314 00316 00320 double ComputeMinimalSampleDistancePerPixel(vtkRenderer *renderer, 00321 vtkVolume *volume); 00323 00332 virtual void GetReductionRatio(double ratio[3]); 00333 00334 int NumberOfCroppingRegions; 00335 00336 // World coordinates of each corner of the dataset. 00337 double BoundingBox[8][3]; 00338 00339 // Used during the clipping process. 00340 vtkPolyData *PolyDataBoundingBox; 00341 vtkPlaneCollection *Planes; 00342 vtkPlane *NearPlane; 00343 00344 vtkClipConvexPolyData *Clip; 00345 vtkMatrix4x4 *InvVolumeMatrix; 00346 00347 vtkDensifyPolyData *Densify; 00348 00349 int OpenGLObjectsCreated; 00350 int NumberOfFrameBuffers; 00351 00352 unsigned int FrameBufferObject; 00353 unsigned int DepthRenderBufferObject; 00354 00355 // 3D scalar texture +1D color+1D opacity+2D grabbed depth buffer 00356 // +1 2D colorbuffer. 00357 unsigned int TextureObjects[5]; 00358 // used in MIP Mode (2 needed for ping-pong technique) 00359 unsigned int MaxValueFrameBuffer; 00360 unsigned int MaxValueFrameBuffer2; 00361 int ReducedSize[2]; 00362 00363 vtkPolyData *ClippedBoundingBox; 00364 00365 int LastSize[2]; 00366 00367 double ReductionFactor; 00368 00369 // Supported extensions 00370 // List of unsupported required extensions. Pimpl. 00371 vtkUnsupportedRequiredExtensionsStringStream *UnsupportedRequiredExtensions; 00372 int LoadExtensionsSucceeded; 00373 00374 int Supports_GL_ARB_texture_float; 00375 int SupportsPixelBufferObjects; 00376 00377 vtkTimeStamp DataBufferTime; 00378 00379 // Matrices used in internal computation. As a member variable, 00380 // only one memory allocation is performed. 00381 vtkMatrix4x4 *TempMatrix[3]; 00382 00383 double TableRange[2]; 00384 00385 // Final string to send to the GPU as the fragment program source code. 00386 // char *FragmentCode; 00387 // int FragmentCodeCapacity; 00388 00389 int ErrorLine; 00390 int ErrorColumn; 00391 char *ErrorString; 00392 00393 // Store the last projection an raycast method in order to not rebuild 00394 // the fragment code at every call. 00395 int LastParallelProjection; 00396 int LastRayCastMethod; 00397 int LastCroppingMode; 00398 int LastComponent; 00399 int LastShade; 00400 00401 vtkImageData *SmallInput; 00402 vtkTimeStamp SmallInputBuildTime; 00403 00406 void BuildScaleBiasProgram(vtkRenderWindow *w); 00407 00408 #if 0 00409 vtkIdType LoadedExtent[6]; 00410 double LoadedBounds[6]; 00411 vtkTimeStamp LoadedScalarTime; 00412 int LoadedCellFlag; // point data or cell data (or field data, not handled) ? 00413 #endif 00414 00415 unsigned int SavedFrameBuffer; // some offscreen mode use a framebuffer too. 00416 00417 vtkTessellatedBoxSource *BoxSource; 00418 00419 float *NoiseTexture; 00420 int NoiseTextureSize; // size of one dimension. 00421 unsigned int NoiseTextureId; // GLuint 00422 00423 bool IgnoreSampleDistancePerPixel; 00424 00425 vtkMapDataArrayTextureId *ScalarsTextures; // need a list for AMR mode. 00426 vtkMapMaskTextureId *MaskTextures; // need a list for AMR mode. 00427 00428 vtkRGBTable *RGBTable; 00429 vtkRGBTable *Mask1RGBTable; 00430 vtkRGBTable *Mask2RGBTable; 00431 00432 vtkOpacityTables *OpacityTables; 00433 00434 vtkKWScalarField *CurrentScalar; 00435 vtkKWMask *CurrentMask; 00436 00437 float ActualSampleDistance; 00438 00439 double LastProgressEventTime; // initial value is 0.0. Expressed in seconds. 00440 00441 bool PreserveOrientation; 00442 00443 vtkShaderProgram2 *Program; 00444 vtkShader2 *Main; 00445 vtkShader2 *Projection; 00446 vtkShader2 *Trace; 00447 vtkShader2 *CroppingShader; 00448 vtkShader2 *Component; 00449 vtkShader2 *Shade; 00450 00451 // Internal Variable used to keep track of whether or render window's size 00452 // changed and therefore we need re-allocation. 00453 bool SizeChanged; 00454 00455 vtkShaderProgram2 *ScaleBiasProgram; 00456 00457 private: 00458 vtkOpenGLGPUVolumeRayCastMapper(const vtkOpenGLGPUVolumeRayCastMapper&); // Not implemented. 00459 void operator=(const vtkOpenGLGPUVolumeRayCastMapper&); // Not implemented. 00460 }; 00461 00462 #endif