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 00245 void BuildProgram(vtkRenderWindow *w, 00246 int parallelProjection, 00247 int raycastMethod, 00248 int shadeMethod, 00249 int componentMethod); 00251 00253 void GetLightingStatus(); 00254 00264 void ComputeReductionFactor(double allocatedTime); 00265 00267 00268 void RenderWholeVolume(vtkRenderer *ren, 00269 vtkVolume *vol); 00271 00273 00274 void RenderRegions(vtkRenderer *ren, 00275 vtkVolume *vol); 00277 00278 // Return abort status (true==abort) 00279 int RenderSubVolume(vtkRenderer *ren, 00280 double bounds[6], 00281 vtkVolume *vol); 00282 00283 void LoadProjectionParameters(vtkRenderer *ren, 00284 vtkVolume *vol); 00285 00287 void ComputeNumberOfCroppingRegions(); 00288 00289 void GetTextureFormat(vtkImageData *input, 00290 unsigned int *internalFormat, 00291 unsigned int *format, 00292 unsigned int *type, 00293 int *componentSize); 00294 00295 bool TestLoadingScalar(unsigned int internalFormat, 00296 unsigned int format, 00297 unsigned int type, 00298 int textureSize[3], 00299 int componentSize); 00300 00301 void SlabsFromDatasetToIndex(double slabsDataSet[6], 00302 double slabsPoints[6]); 00303 00304 void SlabsFromIndexToDataset(double slabsPoints[6], 00305 double slabsDataSet[6]); 00306 00307 const char *GetEnabledString(unsigned char value); 00308 void GetOpenGLState(); 00309 00310 void DebugDisplayBox(vtkPolyData *box); 00311 00312 void UpdateNoiseTexture(); 00313 00315 00319 double ComputeMinimalSampleDistancePerPixel(vtkRenderer *renderer, 00320 vtkVolume *volume); 00322 00331 virtual void GetReductionRatio(double ratio[3]); 00332 00333 int NumberOfCroppingRegions; 00334 00335 // World coordinates of each corner of the dataset. 00336 double BoundingBox[8][3]; 00337 00338 // Used during the clipping process. 00339 vtkPolyData *PolyDataBoundingBox; 00340 vtkPlaneCollection *Planes; 00341 vtkPlane *NearPlane; 00342 00343 vtkClipConvexPolyData *Clip; 00344 vtkMatrix4x4 *InvVolumeMatrix; 00345 00346 vtkDensifyPolyData *Densify; 00347 00348 int OpenGLObjectsCreated; 00349 int NumberOfFrameBuffers; 00350 00351 unsigned int FrameBufferObject; 00352 unsigned int DepthRenderBufferObject; 00353 00354 // 3D scalar texture +1D color+1D opacity+2D grabbed depth buffer 00355 // +1 2D colorbuffer. 00356 unsigned int TextureObjects[5]; 00357 // used in MIP Mode (2 needed for ping-pong technique) 00358 unsigned int MaxValueFrameBuffer; 00359 unsigned int MaxValueFrameBuffer2; 00360 int ReducedSize[2]; 00361 00362 vtkPolyData *ClippedBoundingBox; 00363 00364 int LastSize[2]; 00365 00366 double ReductionFactor; 00367 00368 // Supported extensions 00369 // List of unsupported required extensions. Pimpl. 00370 vtkUnsupportedRequiredExtensionsStringStream *UnsupportedRequiredExtensions; 00371 int LoadExtensionsSucceeded; 00372 00373 int Supports_GL_ARB_texture_float; 00374 int SupportsPixelBufferObjects; 00375 00376 vtkTimeStamp DataBufferTime; 00377 00378 // Matrices used in internal computation. As a member variable, 00379 // only one memory allocation is performed. 00380 vtkMatrix4x4 *TempMatrix[3]; 00381 00382 double TableRange[2]; 00383 00384 // Final string to send to the GPU as the fragment program source code. 00385 // char *FragmentCode; 00386 // int FragmentCodeCapacity; 00387 00388 int ErrorLine; 00389 int ErrorColumn; 00390 char *ErrorString; 00391 00392 // Store the last projection an raycast method in order to not rebuild 00393 // the fragment code at every call. 00394 int LastParallelProjection; 00395 int LastRayCastMethod; 00396 int LastCroppingMode; 00397 int LastComponent; 00398 int LastShade; 00399 00400 vtkImageData *SmallInput; 00401 vtkTimeStamp SmallInputBuildTime; 00402 00405 void BuildScaleBiasProgram(vtkRenderWindow *w); 00406 00407 #if 0 00408 vtkIdType LoadedExtent[6]; 00409 double LoadedBounds[6]; 00410 vtkTimeStamp LoadedScalarTime; 00411 int LoadedCellFlag; // point data or cell data (or field data, not handled) ? 00412 #endif 00413 00414 unsigned int SavedFrameBuffer; // some offscreen mode use a framebuffer too. 00415 00416 vtkTessellatedBoxSource *BoxSource; 00417 00418 float *NoiseTexture; 00419 int NoiseTextureSize; // size of one dimension. 00420 unsigned int NoiseTextureId; // GLuint 00421 00422 bool IgnoreSampleDistancePerPixel; 00423 00424 vtkMapDataArrayTextureId *ScalarsTextures; // need a list for AMR mode. 00425 vtkMapMaskTextureId *MaskTextures; // need a list for AMR mode. 00426 00427 vtkRGBTable *RGBTable; 00428 vtkRGBTable *Mask1RGBTable; 00429 vtkRGBTable *Mask2RGBTable; 00430 00431 vtkOpacityTables *OpacityTables; 00432 00433 vtkKWScalarField *CurrentScalar; 00434 vtkKWMask *CurrentMask; 00435 00436 float ActualSampleDistance; 00437 00438 double LastProgressEventTime; // initial value is 0.0. Expressed in seconds. 00439 00440 bool PreserveOrientation; 00441 00442 vtkShaderProgram2 *Program; 00443 vtkShader2 *Main; 00444 vtkShader2 *Projection; 00445 vtkShader2 *Trace; 00446 vtkShader2 *CroppingShader; 00447 vtkShader2 *Component; 00448 vtkShader2 *Shade; 00449 00450 // Internal Variable used to keep track of whether or render window's size 00451 // changed and therefore we need re-allocation. 00452 bool SizeChanged; 00453 00454 vtkShaderProgram2 *ScaleBiasProgram; 00455 00456 private: 00457 vtkOpenGLGPUVolumeRayCastMapper(const vtkOpenGLGPUVolumeRayCastMapper&); // Not implemented. 00458 void operator=(const vtkOpenGLGPUVolumeRayCastMapper&); // Not implemented. 00459 }; 00460 00461 #endif