00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkMitkGPUVolumeRayCastMapper.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 vtkMitkGPUVolumeRayCastMapper - Ray casting performed on the GPU. 00016 // .SECTION Description 00017 // vtkMitkGPUVolumeRayCastMapper is a volume mapper that performs ray casting on 00018 // the GPU using fragment programs. 00019 // 00020 00021 00022 #ifndef __vtkMitkGPUVolumeRayCastMapper_h 00023 #define __vtkMitkGPUVolumeRayCastMapper_h 00024 00025 #include "vtkVolumeMapper.h" 00026 #include "mitkCommon.h" 00027 #include "MitkExtExports.h" 00028 00029 // Only with VTK 5.6 or above 00030 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION==5) && (VTK_MINOR_VERSION>=6) )) 00031 00032 class vtkVolumeProperty; 00033 class vtkRenderWindow; 00034 00035 //class vtkKWAMRVolumeMapper; // friend class. 00036 00037 class MitkExt_EXPORT vtkMitkGPUVolumeRayCastMapper : public vtkVolumeMapper 00038 { 00039 public: 00040 static vtkMitkGPUVolumeRayCastMapper *New(); 00041 vtkTypeRevisionMacro(vtkMitkGPUVolumeRayCastMapper,vtkVolumeMapper); 00042 void PrintSelf( ostream& os, vtkIndent indent ); 00043 00044 // Description: 00045 // If AutoAdjustSampleDistances is on, the the ImageSampleDistance 00046 // will be varied to achieve the allocated render time of this 00047 // prop (controlled by the desired update rate and any culling in 00048 // use). 00049 vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 ); 00050 vtkGetMacro( AutoAdjustSampleDistances, int ); 00051 vtkBooleanMacro( AutoAdjustSampleDistances, int ); 00052 00053 // Description: 00054 // Set/Get the distance between samples used for rendering 00055 // when AutoAdjustSampleDistances is off, or when this mapper 00056 // has more than 1 second allocated to it for rendering. 00057 // Initial value is 1.0. 00058 vtkSetMacro( SampleDistance, float ); 00059 vtkGetMacro( SampleDistance, float ); 00060 00061 // Description: 00062 // Sampling distance in the XY image dimensions. Default value of 1 meaning 00063 // 1 ray cast per pixel. If set to 0.5, 4 rays will be cast per pixel. If 00064 // set to 2.0, 1 ray will be cast for every 4 (2 by 2) pixels. This value 00065 // will be adjusted to meet a desired frame rate when AutoAdjustSampleDistances 00066 // is on. 00067 vtkSetClampMacro( ImageSampleDistance, float, 0.1f, 100.0f ); 00068 vtkGetMacro( ImageSampleDistance, float ); 00069 00070 // Description: 00071 // This is the minimum image sample distance allow when the image 00072 // sample distance is being automatically adjusted. 00073 vtkSetClampMacro( MinimumImageSampleDistance, float, 0.1f, 100.0f ); 00074 vtkGetMacro( MinimumImageSampleDistance, float ); 00075 00076 // Description: 00077 // This is the maximum image sample distance allow when the image 00078 // sample distance is being automatically adjusted. 00079 vtkSetClampMacro( MaximumImageSampleDistance, float, 0.1f, 100.0f ); 00080 vtkGetMacro( MaximumImageSampleDistance, float ); 00081 00082 00083 // Description: 00084 // Set/Get the window / level applied to the final color. 00085 // This allows brightness / contrast adjustments on the 00086 // final image. 00087 // window is the width of the window. 00088 // level is the center of the window. 00089 // Initial window value is 1.0 00090 // Initial level value is 0.5 00091 // window cannot be null but can be negative, this way 00092 // values will be reversed. 00093 // |window| can be larger than 1.0 00094 // level can be any real value. 00095 vtkSetMacro( FinalColorWindow, float ); 00096 vtkGetMacro( FinalColorWindow, float ); 00097 vtkSetMacro( FinalColorLevel, float ); 00098 vtkGetMacro( FinalColorLevel, float ); 00099 00100 // Description: 00101 // Maximum size of the 3D texture in GPU memory. 00102 // Will default to the size computed from the graphics 00103 // card. Can be adjusted by the user. 00104 vtkSetMacro( MaxMemoryInBytes, vtkIdType ); 00105 vtkGetMacro( MaxMemoryInBytes, vtkIdType ); 00106 00107 // Description: 00108 // Maximum fraction of the MaxMemoryInBytes that should 00109 // be used to hold the texture. Valid values are 0.1 to 00110 // 1.0. 00111 vtkSetClampMacro( MaxMemoryFraction, float, 0.1f, 1.0f ); 00112 vtkGetMacro( MaxMemoryFraction, float ); 00113 00114 // Description: 00115 // Tells if the mapper will report intermediate progress. 00116 // Initial value is true. As the progress works with a GL blocking 00117 // call (glFinish()), this can be useful for huge dataset but can 00118 // slow down rendering of small dataset. It should be set to true 00119 // for big dataset or complex shading and streaming but to false for 00120 // small datasets. 00121 vtkSetMacro(ReportProgress,bool); 00122 vtkGetMacro(ReportProgress,bool); 00123 00124 // Description: 00125 // Based on hardware and properties, we may or may not be able to 00126 // render using 3D texture mapping. This indicates if 3D texture 00127 // mapping is supported by the hardware, and if the other extensions 00128 // necessary to support the specific properties are available. 00129 virtual int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window), 00130 vtkVolumeProperty *vtkNotUsed(property)) 00131 { 00132 return 0; 00133 } 00134 00135 void CreateCanonicalView( vtkRenderer *ren, 00136 vtkVolume *volume, 00137 vtkImageData *image, 00138 int blend_mode, 00139 double viewDirection[3], 00140 double viewUp[3] ); 00141 00142 void SetMaskInput(vtkImageData *mask); 00143 vtkGetObjectMacro(MaskInput, vtkImageData); 00144 00145 // Description: 00146 // Tells how much mask color transfer function is used compared to the 00147 // standard color transfer function when the mask is true. 00148 // 0.0 means only standard color transfer function. 00149 // 1.0 means only mask color tranfer function. 00150 // Initial value is 1.0. 00151 vtkSetClampMacro(MaskBlendFactor,float,0.0f,1.0f); 00152 vtkGetMacro(MaskBlendFactor,float); 00153 00154 //BTX 00155 // Description: 00156 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 00157 // Initialize rendering for this volume. 00158 void Render( vtkRenderer *, vtkVolume * ); 00159 00160 // Description: 00161 // Handled in the subclass - the actual render method 00162 // \pre input is up-to-date. 00163 virtual void GPURender( vtkRenderer *, vtkVolume *) {} 00164 00165 // Description: 00166 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 00167 // Release any graphics resources that are being consumed by this mapper. 00168 // The parameter window could be used to determine which graphic 00169 // resources to release. 00170 void ReleaseGraphicsResources(vtkWindow *) {}; 00171 00172 // Description: 00173 // Return how much the dataset has to be reduced in each dimension to 00174 // fit on the GPU. If the value is 1.0, there is no need to reduce the 00175 // dataset. 00176 // \pre the calling thread has a current OpenGL context. 00177 // \pre mapper_supported: IsRenderSupported(renderer->GetRenderWindow(),0) 00178 // The computation is based on hardware limits (3D texture indexable size) 00179 // and MaxMemoryInBytes. 00180 // \post valid_i_ratio: ratio[0]>0 && ratio[0]<=1.0 00181 // \post valid_j_ratio: ratio[1]>0 && ratio[1]<=1.0 00182 // \post valid_k_ratio: ratio[2]>0 && ratio[2]<=1.0 00183 virtual void GetReductionRatio(double ratio[3])=0; 00184 00185 //ETX 00186 00187 protected: 00188 vtkMitkGPUVolumeRayCastMapper(); 00189 ~vtkMitkGPUVolumeRayCastMapper(); 00190 00191 // Check to see that the render will be OK 00192 int ValidateRender( vtkRenderer *, vtkVolume * ); 00193 00194 00195 // Special version of render called during the creation 00196 // of a canonical view. 00197 void CanonicalViewRender( vtkRenderer *, vtkVolume * ); 00198 00199 // Methods called by the AMR Volume Mapper. 00200 virtual void PreRender(vtkRenderer *ren, 00201 vtkVolume *vol, 00202 double datasetBounds[6], 00203 double scalarRange[2], 00204 int numberOfScalarComponents, 00205 unsigned int numberOfLevels)=0; 00206 00207 // \pre input is up-to-date 00208 virtual void RenderBlock(vtkRenderer *ren, 00209 vtkVolume *vol, 00210 unsigned int level)=0; 00211 00212 virtual void PostRender(vtkRenderer *ren, 00213 int numberOfScalarComponents)=0; 00214 00215 // Description: 00216 // Called by the AMR Volume Mapper. 00217 // Set the flag that tells if the scalars are on point data (0) or 00218 // cell data (1). 00219 void SetCellFlag(int cellFlag); 00220 00221 // The distance between sample points along the ray 00222 float SampleDistance; 00223 00224 00225 float ImageSampleDistance; 00226 float MinimumImageSampleDistance; 00227 float MaximumImageSampleDistance; 00228 int AutoAdjustSampleDistances; 00229 00230 int SmallVolumeRender; 00231 double BigTimeToDraw; 00232 double SmallTimeToDraw; 00233 00234 float FinalColorWindow; 00235 float FinalColorLevel; 00236 00237 vtkIdType MaxMemoryInBytes; 00238 float MaxMemoryFraction; 00239 00240 00241 // 1 if we are generating the canonical image, 0 otherwise 00242 int GeneratingCanonicalView; 00243 vtkImageData *CanonicalViewImageData; 00244 00245 // Description: 00246 // Set the mapper in AMR Mode or not. Initial value is false. 00247 // Called only by the vtkKWAMRVolumeMapper 00248 vtkSetClampMacro(AMRMode,int,0,1); 00249 vtkGetMacro(AMRMode,int); 00250 vtkBooleanMacro(AMRMode,int); 00251 00252 int AMRMode; 00253 int CellFlag; // point data or cell data (or field data, not handled) ? 00254 00255 // Description: 00256 // Compute the cropping planes clipped by the bounds of the volume. 00257 // The result is put into this->ClippedCroppingRegionPlanes. 00258 // NOTE: IT WILL BE MOVED UP TO vtkVolumeMapper after bullet proof usage 00259 // in this mapper. Other subclasses will use the ClippedCroppingRegionsPlanes 00260 // members instead of CroppingRegionPlanes. 00261 // \pre volume_exists: this->GetInput()!=0 00262 // \pre valid_cropping: this->Cropping && 00263 // this->CroppingRegionPlanes[0]<this->CroppingRegionPlanes[1] && 00264 // this->CroppingRegionPlanes[2]<this->CroppingRegionPlanes[3] && 00265 // this->CroppingRegionPlanes[4]<this->CroppingRegionPlanes[5]) 00266 virtual void ClipCroppingRegionPlanes(); 00267 00268 double ClippedCroppingRegionPlanes[6]; 00269 00270 bool ReportProgress; 00271 00272 vtkImageData *MaskInput; 00273 00274 float MaskBlendFactor; 00275 00276 vtkGetObjectMacro(TransformedInput, vtkImageData); 00277 void SetTransformedInput(vtkImageData*); 00278 00279 vtkImageData* TransformedInput; 00280 00281 // Description: 00282 // This is needed only to check if the input data has been changed since the last 00283 // Render() call. 00284 vtkImageData* LastInput; 00285 00286 private: 00287 vtkMitkGPUVolumeRayCastMapper(const vtkMitkGPUVolumeRayCastMapper&); // Not implemented. 00288 void operator=(const vtkMitkGPUVolumeRayCastMapper&); // Not implemented. 00289 }; 00290 00291 #endif 00292 00293 #endif 00294