|
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: 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 "VolumeRenderingReplacementsExport.h" 00072 00073 00074 class vtkImageData; 00075 class vtkColorTransferFunction; 00076 class vtkPiecewiseFunction; 00077 class vtkRenderWindow; 00078 class vtkVolumeProperty; 00079 00081 class Q_SLICER_QTMODULES_VOLUMERENDERING_REPLACEMENTS_EXPORT vtkSlicerVolumeTextureMapper3D : public vtkVolumeMapper 00082 { 00083 public: 00084 vtkTypeRevisionMacro(vtkSlicerVolumeTextureMapper3D,vtkVolumeMapper); 00085 void PrintSelf(ostream& os, vtkIndent indent); 00086 00087 static vtkSlicerVolumeTextureMapper3D *New(); 00088 00089 // Description: 00090 // The distance at which to space sampling planes. This 00091 // may not be honored for interactive renders. An interactive 00092 // render is defined as one that has less than 1 second of 00093 // allocated render time. 00094 vtkSetMacro( SampleDistance, float ); 00095 vtkGetMacro( SampleDistance, float ); 00096 00097 // Description: 00098 // Desired frame rate 00099 vtkSetMacro(Framerate, float); 00100 vtkGetMacro(Framerate, float); 00101 00102 // Description: 00103 // set internal volume size 00104 void SetInternalVolumeSize(int size); 00105 00106 // Description: 00107 // These are the dimensions of the 3D texture 00108 vtkGetVectorMacro( VolumeDimensions, int, 3 ); 00109 00110 // Description: 00111 // This is the spacing of the 3D texture 00112 vtkGetVectorMacro( VolumeSpacing, float, 3 ); 00113 00114 // Description: 00115 // Based on hardware and properties, we may or may not be able to 00116 // render using 3D texture mapping. This indicates if 3D texture 00117 // mapping is supported by the hardware, and if the other extensions 00118 // necessary to support the specific properties are available. 00119 virtual int IsRenderSupported(vtkRenderWindow*, vtkVolumeProperty * ) {return 0;}; 00120 00121 // Description: 00122 // Allow access to the number of polygons used for the 00123 // rendering. 00124 vtkGetMacro( NumberOfPolygons, int ); 00125 00126 // Description: 00127 // Allow access to the actual sample distance used to render 00128 // the image. 00129 vtkGetMacro( ActualSampleDistance, float ); 00130 00131 00132 // Description: 00133 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 00134 // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS 00135 // Render the volume 00136 virtual void Render(vtkRenderer *, vtkVolume *) {}; 00137 00138 // Description: 00139 // What rendering method is supported? 00140 enum 00141 { 00142 FRAGMENT_PROGRAM_METHOD=0, 00143 NVIDIA_METHOD=1, 00144 ATI_METHOD=2, 00145 NO_METHOD=3 00146 }; 00147 00148 // Description: 00149 // Set the preferred render method. If it is supported, this 00150 // one will be used. Don't allow ATI_METHOD - it is not actually 00151 // supported. 00152 vtkSetClampMacro( PreferredRenderMethod, int, 00153 vtkSlicerVolumeTextureMapper3D::FRAGMENT_PROGRAM_METHOD, 00154 vtkSlicerVolumeTextureMapper3D::NVIDIA_METHOD ); 00155 void SetPreferredMethodToFragmentProgram() 00156 { this->SetPreferredRenderMethod( vtkSlicerVolumeTextureMapper3D::FRAGMENT_PROGRAM_METHOD ); } 00157 void SetPreferredMethodToNVidia() 00158 { this->SetPreferredRenderMethod( vtkSlicerVolumeTextureMapper3D::NVIDIA_METHOD ); } 00159 00160 00161 00162 protected: 00163 vtkSlicerVolumeTextureMapper3D(); 00164 ~vtkSlicerVolumeTextureMapper3D(); 00165 00166 float Framerate; 00167 float *PolygonBuffer; 00168 float *IntersectionBuffer; 00169 int NumberOfPolygons; 00170 int BufferSize; 00171 int InternalVolumeSize; 00172 unsigned char *Volume1; 00173 unsigned char *Volume2; 00174 unsigned char *Volume3; 00175 int VolumeSize; 00176 int VolumeComponents; 00177 int VolumeDimensions[3]; 00178 float VolumeSpacing[3]; 00179 00180 float SampleDistance; 00181 float ActualSampleDistance; 00182 00183 vtkImageData *SavedTextureInput; 00184 vtkImageData *SavedParametersInput; 00185 00186 vtkColorTransferFunction *SavedRGBFunction; 00187 vtkPiecewiseFunction *SavedGrayFunction; 00188 vtkPiecewiseFunction *SavedScalarOpacityFunction; 00189 vtkPiecewiseFunction *SavedGradientOpacityFunction; 00190 int SavedColorChannels; 00191 float SavedSampleDistance; 00192 float SavedScalarOpacityDistance; 00193 00194 unsigned char ColorLookup[65536*4]; 00195 unsigned char AlphaLookup[65536]; 00196 float TempArray1[3*4096]; 00197 float TempArray2[4096]; 00198 int ColorTableSize; 00199 float ColorTableScale; 00200 float ColorTableOffset; 00201 00202 unsigned char DiffuseLookup[65536*4]; 00203 unsigned char SpecularLookup[65536*4]; 00204 00205 vtkTimeStamp SavedTextureMTime; 00206 vtkTimeStamp SavedParametersMTime; 00207 00208 int RenderMethod; 00209 int PreferredRenderMethod; 00210 00211 // Description: 00212 // For the given viewing direction, compute the set of polygons. 00213 void ComputePolygons( vtkRenderer *ren, vtkVolume *vol, double bounds[6] ); 00214 00215 // Description: 00216 // Update the internal RGBA representation of the volume. Return 1 if 00217 // anything change, 0 if nothing changed. 00218 int UpdateVolumes( vtkVolume * ); 00219 int UpdateColorLookup( vtkVolume * ); 00220 00221 // Description: 00222 // Impemented in subclass - check is texture size is OK. 00223 virtual int IsTextureSizeSupported( int [3] ) {return 0;}; 00224 00225 private: 00226 vtkSlicerVolumeTextureMapper3D(const vtkSlicerVolumeTextureMapper3D&); // Not implemented. 00227 void operator=(const vtkSlicerVolumeTextureMapper3D&); // Not implemented. 00228 }; 00229 00230 00231 #endif 00232 00233 00234 00235 00236 00237
1.7.4