VTK
dox/VolumeRendering/vtkSmartVolumeMapper.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkFixedPointRayCastImage.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 =========================================================================*/
00108 #ifndef __vtkSmartVolumeMapper_h
00109 #define __vtkSmartVolumeMapper_h
00110 
00111 #include "vtkVolumeMapper.h"
00112 #include "vtkImageReslice.h" // for VTK_RESLICE_NEAREST, VTK_RESLICE_CUBIC
00113 
00114 class vtkFixedPointVolumeRayCastMapper;
00115 class vtkGPUVolumeRayCastMapper;
00116 class vtkImageResample;
00117 class vtkRenderWindow;
00118 class vtkVolume;
00119 class vtkVolumeProperty;
00120 class vtkVolumeTextureMapper3D;
00121 
00122 class VTK_VOLUMERENDERING_EXPORT vtkSmartVolumeMapper : public vtkVolumeMapper
00123 {
00124 public:
00125   static vtkSmartVolumeMapper *New();
00126   vtkTypeMacro(vtkSmartVolumeMapper,vtkVolumeMapper);
00127   void PrintSelf( ostream& os, vtkIndent indent );
00128 
00130 
00136   vtkSetMacro( FinalColorWindow, float );
00138 
00140 
00141   vtkGetMacro( FinalColorWindow, float );
00143 
00145 
00149   vtkSetMacro( FinalColorLevel,  float );
00151 
00153 
00154   vtkGetMacro( FinalColorLevel,  float );
00156 
00157 //BTX
00158 // The possible values for the default and current render mode ivars
00159   enum
00160   {
00161     DefaultRenderMode=0,
00162     RayCastAndTextureRenderMode,
00163     RayCastRenderMode,
00164     TextureRenderMode,
00165     GPURenderMode,
00166     UndefinedRenderMode,
00167     InvalidRenderMode
00168   };
00169 //ETX
00170 
00173   void SetRequestedRenderMode(int mode);
00174 
00179   void SetRequestedRenderModeToDefault();
00180 
00186   void SetRequestedRenderModeToRayCastAndTexture();
00187 
00192   void SetRequestedRenderModeToRayCast();
00193 
00195 
00196   vtkGetMacro( RequestedRenderMode, int );
00198 
00200 
00205   vtkSetClampMacro( InteractiveUpdateRate, double, 1.0e-10, 1.0e10 );
00207 
00209 
00211   vtkGetMacro( InteractiveUpdateRate, double );
00213 
00216   int GetLastUsedRenderMode();
00217 
00219 
00223   vtkSetMacro( MaxMemoryInBytes, vtkIdType );
00224   vtkGetMacro( MaxMemoryInBytes, vtkIdType );
00226 
00228 
00231   vtkSetClampMacro( MaxMemoryFraction, float, 0.1f, 1.0f );
00232   vtkGetMacro( MaxMemoryFraction, float );
00234 
00236 
00238   vtkSetClampMacro(InterpolationMode, int,
00239                    VTK_RESLICE_NEAREST, VTK_RESLICE_CUBIC);
00240   vtkGetMacro(InterpolationMode, int);
00241   void SetInterpolationModeToNearestNeighbor();
00242   void SetInterpolationModeToLinear();
00243   void SetInterpolationModeToCubic();
00245 
00247 
00250   void CreateCanonicalView( vtkRenderer *ren,
00251                             vtkVolume *volume,
00252                             vtkVolume *volume2,
00253                             vtkImageData *image,
00254                             int blend_mode,
00255                             double viewDirection[3],
00256                             double viewUp[3] );
00258 
00259 
00260 //BTX
00263   void Render( vtkRenderer *, vtkVolume * );
00264 
00266 
00270   void ReleaseGraphicsResources(vtkWindow *);
00271 //ETX
00273 
00274 protected:
00275   vtkSmartVolumeMapper();
00276   ~vtkSmartVolumeMapper();
00277 
00281   void ConnectMapperInput(vtkVolumeMapper *m);
00282 
00286   void ConnectFilterInput(vtkImageResample *f);
00287 
00288   // Window / level ivars
00289   float   FinalColorWindow;
00290   float   FinalColorLevel;
00291 
00292   // GPU mapper-specific memory ivars.
00293   vtkIdType MaxMemoryInBytes;
00294   float MaxMemoryFraction;
00295 
00296   // Used for downsampling.
00297   int InterpolationMode;
00298 
00299   // The requested render mode is used to compute the current render mode. Note
00300   // that the current render mode can be invalid if the requested mode is not
00301   // supported.
00302   int     RequestedRenderMode;
00303   int     CurrentRenderMode;
00304 
00305   // Initialization variables.
00306   int          Initialized;
00307   vtkTimeStamp SupportStatusCheckTime;
00308   int          TextureSupported;
00309   int          GPUSupported;
00310   int          RayCastSupported;
00311   int          LowResGPUNecessary;
00312 
00313   // This is the resample filter that may be used if we need to
00314   // create a low resolution version of the volume for GPU rendering
00315   vtkImageResample *GPUResampleFilter;
00316 
00317   // If the DesiredUpdateRate of the vtkRenderWindow causing the Render is at
00318   // or above this value, the render is considered interactive. Otherwise it is
00319   // considered still.
00320   double InteractiveUpdateRate;
00321 
00322   // The initialize method. Called from ComputeRenderMode whenever something
00323   // relevant has changed.
00324   void  Initialize(vtkRenderer *ren,
00325                    vtkVolume *vol);
00326 
00327   // The method that computes the render mode from the requested render mode
00328   // based on the support status for each render method.
00329   void  ComputeRenderMode(vtkRenderer *ren,
00330                           vtkVolume *vol);
00331 
00332   // The three potential mappers
00333   vtkGPUVolumeRayCastMapper      *GPULowResMapper;
00334   vtkGPUVolumeRayCastMapper      *GPUMapper;
00335   vtkFixedPointVolumeRayCastMapper  *RayCastMapper;
00336   vtkVolumeTextureMapper3D          *TextureMapper;
00337 
00338 
00339   // We need to keep track of the blend mode we had when we initialized
00340   // because we need to reinitialize (and recheck hardware support) if
00341   // it changes
00342   int  InitializedBlendMode;
00343 
00344 private:
00345   vtkSmartVolumeMapper(const vtkSmartVolumeMapper&);  // Not implemented.
00346   void operator=(const vtkSmartVolumeMapper&);  // Not implemented.
00347 };
00348 
00349 #endif