|
Slicer 4.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkSlicerGPUVolumeMapper.h,v $ 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 =========================================================================*/ 00015 // .NAME vtkSlicerGPUVolumeMapper - GPU volume render with 3D texture mapping (GLSL) 00016 00017 // .SECTION Description 00018 // vtkSlicerGPUVolumeMapper renders a volume using 3D texture mapping in fragment shader. 00019 // This class is actually an abstract superclass - with all the actual 00020 // work done by vtkSlicerGPURayCastVolumeTextureMapper3D. 00021 // 00022 // This mappers currently supports: 00023 // 00024 // - any data type as input 00025 // - one component, or two or four non-independent components 00026 // - composite blending 00027 // - intermixed opaque geometry 00028 // - multiple volumes can be rendered if they can 00029 // be sorted into back-to-front order (use the vtkFrustumCoverageCuller) 00030 // 00031 // This mapper does not support: 00032 // - more than one independent component 00033 // - maximum intensity projection 00034 // 00035 // Internally, this mapper will potentially change the resolution of the 00036 // input data. The data will be resampled to be a power of two in each 00037 // direction, and also no greater than 128*256*256 voxels (any aspect) 00038 // for one or two component data, or 128*128*256 voxels (any aspect) 00039 // for four component data. The limits are currently hardcoded after 00040 // a check using the GL_PROXY_TEXTURE3D because some graphics drivers 00041 // were always responding "yes" to the proxy call despite not being 00042 // able to allocate that much texture memory. 00043 // 00044 // Currently, calculations are computed using 8 bits per RGBA channel. 00045 // In the future this should be expanded to handle newer boards that 00046 // can support 15 bit float compositing. 00047 // 00048 00049 // .SECTION see also 00050 // vtkVolumeMapper 00051 00052 #ifndef __vtkSlicerGPUVolumeMapper_h 00053 #define __vtkSlicerGPUVolumeMapper_h 00054 00055 #include "vtkVolumeMapper.h" 00056 #include "VolumeRenderingReplacementsExport.h" 00057 00058 00059 class vtkMultiThreader; 00060 class vtkImageData; 00061 class vtkColorTransferFunction; 00062 class vtkPiecewiseFunction; 00063 class vtkRenderWindow; 00064 class vtkVolumeProperty; 00065 00066 VTK_THREAD_RETURN_TYPE vtkSlicerGPUVolumeMapperComputeGradients(void *arg); 00067 00069 class vtkSlicerGPUVolumeMapper; 00070 struct GradientsArgsType 00071 { 00072 float *dataPtr; 00073 vtkSlicerGPUVolumeMapper *me; 00074 double scalarRange[2]; 00075 unsigned char *volume1; 00076 unsigned char *volume2; 00077 }; 00078 00080 class Q_SLICER_QTMODULES_VOLUMERENDERING_REPLACEMENTS_EXPORT vtkSlicerGPUVolumeMapper 00081 : public vtkVolumeMapper 00082 { 00083 public: 00084 vtkTypeRevisionMacro(vtkSlicerGPUVolumeMapper,vtkVolumeMapper); 00085 void PrintSelf(ostream& os, vtkIndent indent); 00086 00087 static vtkSlicerGPUVolumeMapper *New(); 00088 00089 // Description: 00090 // Desired frame rate 00091 vtkSetMacro(Framerate, float); 00092 vtkGetMacro(Framerate, float); 00093 00094 // Description: 00095 // These are the dimensions of the 3D texture 00096 vtkGetVectorMacro( VolumeDimensions, int, 3 ); 00097 00098 // Description: 00099 // This is the spacing of the 3D texture 00100 vtkGetVectorMacro( VolumeSpacing, float, 3 ); 00101 00102 // Description: 00103 // Based on hardware and properties, we may or may not be able to 00104 // render using 3D texture mapping. This indicates if 3D texture 00105 // mapping is supported by the hardware, and if the other extensions 00106 // necessary to support the specific properties are available. 00107 virtual int IsRenderSupported(vtkRenderWindow *, vtkVolumeProperty *) {return 0;}; 00108 00109 00110 // Description: 00111 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 00112 // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS 00113 // Render the volume 00114 virtual void Render(vtkRenderer *, vtkVolume *) {}; 00115 00116 protected: 00117 vtkSlicerGPUVolumeMapper(); 00118 ~vtkSlicerGPUVolumeMapper(); 00119 00120 float ScalarOffset; 00121 float ScalarScale; 00122 00123 float Framerate; 00124 00125 unsigned char *Volume1; 00126 unsigned char *Volume2; 00127 int VolumeSize; 00128 int VolumeComponents; 00129 int VolumeDimensions[3]; 00130 float VolumeSpacing[3]; 00131 00132 vtkImageData *SavedTextureInput; 00133 vtkImageData *SavedParametersInput; 00134 00135 vtkColorTransferFunction *SavedRGBFunction; 00136 vtkPiecewiseFunction *SavedGrayFunction; 00137 vtkPiecewiseFunction *SavedScalarOpacityFunction; 00138 vtkPiecewiseFunction *SavedGradientOpacityFunction; 00139 int SavedColorChannels; 00140 float SavedScalarOpacityDistance; 00141 00142 unsigned char ColorLookup[65536*4]; 00143 float TempArray1[3*4096]; 00144 float TempArray2[4096]; 00145 int ColorTableSize; 00146 00147 vtkTimeStamp SavedTextureMTime; 00148 vtkTimeStamp SavedParametersMTime; 00149 00150 vtkMultiThreader *Threader; 00151 00152 GradientsArgsType *GradientsArgs; 00153 00154 // Description: 00155 // Update the internal RGBA representation of the volume. Return 1 if 00156 // anything change, 0 if nothing changed. 00157 int UpdateVolumes( vtkVolume * ); 00158 int UpdateColorLookup( vtkVolume * ); 00159 00160 void CopyToFloatBuffer(vtkImageData* input, float* floatDataPtr, int dataPtrSize); 00161 00162 // Description: 00163 // Impemented in subclass - check is texture size is OK. 00164 virtual int IsTextureSizeSupported( int [3] ) {return 0;}; 00165 00166 friend VTK_THREAD_RETURN_TYPE vtkSlicerGPUVolumeMapperComputeGradients( void *arg ); 00167 00168 private: 00169 vtkSlicerGPUVolumeMapper(const vtkSlicerGPUVolumeMapper&); // Not implemented. 00170 void operator=(const vtkSlicerGPUVolumeMapper&); // Not implemented. 00171 }; 00172 00173 00174 #endif 00175 00176 00177 00178 00179 00180
1.7.4