00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkSlicerVolumeTextureMapper3D.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 vtkSlicerVolumeTextureMapper3D - volume render with 3D texture mapping 00016 00017 // .SECTION Description 00018 // vtkSlicerVolumeTextureMapper3D renders a volume using 3D texture mapping. 00019 // This class is actually an abstract superclass - with all the actual 00020 // work done by vtkSlicerOpenGLVolumeTextureMapper3D. 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 // This mapper supports two main families of graphics hardware: 00049 // nvidia and ATI. There are two different implementations of 00050 // 3D texture mapping used - one based on nvidia's GL_NV_texture_shader2 00051 // and GL_NV_register_combiners2 extension, and one based on 00052 // ATI's GL_ATI_fragment_shader (supported also by some nvidia boards) 00053 // To use this class in an application that will run on various 00054 // hardware configurations, you should have a back-up volume rendering 00055 // method. You should create a vtkSlicerVolumeTextureMapper3D, assign its 00056 // input, make sure you have a current OpenGL context (you've rendered 00057 // at least once), then call IsRenderSupported with a vtkVolumeProperty 00058 // as an argument. This method will return 0 if the input has more than 00059 // one independent component, or if the graphics hardware does not 00060 // support the set of required extensions for using at least one of 00061 // the two implemented methods (nvidia or ati) 00062 // 00063 00064 // .SECTION see also 00065 // vtkVolumeMapper 00066 00067 #ifndef __vtkSlicerVolumeTextureMapper3D_h 00068 #define __vtkSlicerVolumeTextureMapper3D_h 00069 00070 #include "vtkVolumeMapper.h" 00071 #include "vtkVolumeRenderingReplacements.h" 00072 00073 class vtkImageData; 00074 class vtkColorTransferFunction; 00075 class vtkPiecewiseFunction; 00076 class vtkVolumeProperty; 00077 00078 class VTK_VOLUMERENDERINGREPLACEMENTS1_EXPORT vtkSlicerVolumeTextureMapper3D : public vtkVolumeMapper 00079 { 00080 public: 00081 vtkTypeRevisionMacro(vtkSlicerVolumeTextureMapper3D,vtkVolumeMapper); 00082 void PrintSelf(ostream& os, vtkIndent indent); 00083 00084 static vtkSlicerVolumeTextureMapper3D *New(); 00085 00086 // Description: 00087 // The distance at which to space sampling planes. This 00088 // may not be honored for interactive renders. An interactive 00089 // render is defined as one that has less than 1 second of 00090 // allocated render time. 00091 vtkSetMacro( SampleDistance, float ); 00092 vtkGetMacro( SampleDistance, float ); 00093 00094 // Description: 00095 // Desired frame rate 00096 vtkSetMacro(Framerate, float); 00097 vtkGetMacro(Framerate, float); 00098 00099 // Description: 00100 // These are the dimensions of the 3D texture 00101 vtkGetVectorMacro( VolumeDimensions, int, 3 ); 00102 00103 // Description: 00104 // This is the spacing of the 3D texture 00105 vtkGetVectorMacro( VolumeSpacing, float, 3 ); 00106 00107 // Description: 00108 // Based on hardware and properties, we may or may not be able to 00109 // render using 3D texture mapping. This indicates if 3D texture 00110 // mapping is supported by the hardware, and if the other extensions 00111 // necessary to support the specific properties are available. 00112 virtual int IsRenderSupported( vtkVolumeProperty * ) {return 0;}; 00113 00114 // Description: 00115 // Allow access to the number of polygons used for the 00116 // rendering. 00117 vtkGetMacro( NumberOfPolygons, int ); 00118 00119 // Description: 00120 // Allow access to the actual sample distance used to render 00121 // the image. 00122 vtkGetMacro( ActualSampleDistance, float ); 00123 00124 //BTX 00125 00126 // Description: 00127 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 00128 // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS 00129 // Render the volume 00130 virtual void Render(vtkRenderer *, vtkVolume *) {}; 00131 00132 // Description: 00133 // What rendering method is supported? 00134 enum 00135 { 00136 FRAGMENT_PROGRAM_METHOD=0, 00137 NVIDIA_METHOD=1, 00138 ATI_METHOD=2, 00139 NO_METHOD=3 00140 }; 00141 //ETX 00142 00143 // Description: 00144 // Set the preferred render method. If it is supported, this 00145 // one will be used. Don't allow ATI_METHOD - it is not actually 00146 // supported. 00147 vtkSetClampMacro( PreferredRenderMethod, int, 00148 vtkSlicerVolumeTextureMapper3D::FRAGMENT_PROGRAM_METHOD, 00149 vtkSlicerVolumeTextureMapper3D::NVIDIA_METHOD ); 00150 void SetPreferredMethodToFragmentProgram() 00151 { this->SetPreferredRenderMethod( vtkSlicerVolumeTextureMapper3D::FRAGMENT_PROGRAM_METHOD ); } 00152 void SetPreferredMethodToNVidia() 00153 { this->SetPreferredRenderMethod( vtkSlicerVolumeTextureMapper3D::NVIDIA_METHOD ); } 00154 00155 00156 00157 protected: 00158 vtkSlicerVolumeTextureMapper3D(); 00159 ~vtkSlicerVolumeTextureMapper3D(); 00160 00161 float Framerate; 00162 float *PolygonBuffer; 00163 float *IntersectionBuffer; 00164 int NumberOfPolygons; 00165 int BufferSize; 00166 00167 unsigned char *Volume1; 00168 unsigned char *Volume2; 00169 unsigned char *Volume3; 00170 int VolumeSize; 00171 int VolumeComponents; 00172 int VolumeDimensions[3]; 00173 float VolumeSpacing[3]; 00174 00175 float SampleDistance; 00176 float ActualSampleDistance; 00177 00178 vtkImageData *SavedTextureInput; 00179 vtkImageData *SavedParametersInput; 00180 00181 vtkColorTransferFunction *SavedRGBFunction; 00182 vtkPiecewiseFunction *SavedGrayFunction; 00183 vtkPiecewiseFunction *SavedScalarOpacityFunction; 00184 vtkPiecewiseFunction *SavedGradientOpacityFunction; 00185 int SavedColorChannels; 00186 float SavedSampleDistance; 00187 float SavedScalarOpacityDistance; 00188 00189 unsigned char ColorLookup[65536*4]; 00190 unsigned char AlphaLookup[65536]; 00191 float TempArray1[3*4096]; 00192 float TempArray2[4096]; 00193 int ColorTableSize; 00194 float ColorTableScale; 00195 float ColorTableOffset; 00196 00197 unsigned char DiffuseLookup[65536*4]; 00198 unsigned char SpecularLookup[65536*4]; 00199 00200 vtkTimeStamp SavedTextureMTime; 00201 vtkTimeStamp SavedParametersMTime; 00202 00203 int RenderMethod; 00204 int PreferredRenderMethod; 00205 00206 // Description: 00207 // For the given viewing direction, compute the set of polygons. 00208 void ComputePolygons( vtkRenderer *ren, vtkVolume *vol, double bounds[6] ); 00209 00210 // Description: 00211 // Update the internal RGBA representation of the volume. Return 1 if 00212 // anything change, 0 if nothing changed. 00213 int UpdateVolumes( vtkVolume * ); 00214 int UpdateColorLookup( vtkVolume * ); 00215 00216 // Description: 00217 // Impemented in subclass - check is texture size is OK. 00218 //BTX 00219 virtual int IsTextureSizeSupported( int [3] ) {return 0;}; 00220 //ETX 00221 00222 private: 00223 vtkSlicerVolumeTextureMapper3D(const vtkSlicerVolumeTextureMapper3D&); // Not implemented. 00224 void operator=(const vtkSlicerVolumeTextureMapper3D&); // Not implemented. 00225 }; 00226 00227 00228 #endif 00229 00230 00231 00232 00233 00234
1.6.1