00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00055 #ifndef __vtkVolumeRayCastMapper_h
00056 #define __vtkVolumeRayCastMapper_h
00057 
00058 #include "vtkVolumeMapper.h"
00059 #include "vtkMultiThreader.h"
00060 #include "vtkVolumeRayCastFunction.h"
00061 #include "vtkRayBounder.h"
00062 #include "vtkEncodedGradientShader.h"
00063 #include "vtkEncodedGradientEstimator.h"
00064 
00065 class vtkRenderer;
00066 class vtkVolume;
00067 class vtkVolumeTransform;
00068 class vtkPlaneCollection;
00069 
00070 
00071 #define vtkFloorFuncMacro(x)   (((x) < 0.0)?((int)((x)-1.0)):((int)(x)))
00072 
00073 
00074 #define vtkRoundFuncMacro(x)   (int)((x)+0.5)
00075 
00076 
00077 
00078 
00079 #define vtkTrilinFuncMacro(v,x,y,z,a,b,c,d,e,f,g,h)         \
00080         t00 =   a + (x)*(b-a);      \
00081         t01 =   c + (x)*(d-c);      \
00082         t10 =   e + (x)*(f-e);      \
00083         t11 =   g + (x)*(h-g);      \
00084         t0  = t00 + (y)*(t01-t00);  \
00085         t1  = t10 + (y)*(t11-t10);  \
00086         v   =  t0 + (z)*(t1-t0);
00087 
00088 class VTK_EXPORT vtkVolumeRayCastMapper : public vtkVolumeMapper
00089 {
00090 public:
00091   static vtkVolumeRayCastMapper *New();
00092   vtkTypeMacro(vtkVolumeRayCastMapper,vtkVolumeMapper);
00093   void PrintSelf( ostream& os, vtkIndent index );
00094 
00101   vtkSetMacro( SampleDistance, float );
00102   vtkGetMacro( SampleDistance, float );
00103 
00106   vtkSetObjectMacro( RayBounder, vtkRayBounder );
00107   vtkGetObjectMacro( RayBounder, vtkRayBounder );
00108 
00111   vtkSetObjectMacro( VolumeRayCastFunction, vtkVolumeRayCastFunction );
00112   vtkGetObjectMacro( VolumeRayCastFunction, vtkVolumeRayCastFunction );
00113 
00115   void SetGradientEstimator( vtkEncodedGradientEstimator *gradest );
00116   vtkGetObjectMacro( GradientEstimator, vtkEncodedGradientEstimator );
00117 
00119   vtkGetObjectMacro( GradientShader, vtkEncodedGradientShader );
00120 
00121 
00124   void Render( vtkRenderer *, vtkVolume * ) {};
00125 
00127   void InitializeRender( vtkRenderer *ren, vtkVolume *vol,
00128           VTKRayCastVolumeInfo *volumeInfo );
00129 
00134   void ReleaseGraphicsResources(vtkWindow *);
00135 
00138   float GetZeroOpacityThreshold( vtkVolume *vol );
00139 
00141   void CastViewRay( VTKRayCastRayInfo *rayInfo,
00142           VTKRayCastVolumeInfo *volumeInfo );
00143 
00145   int GetMapperType() { return VTK_RAYCAST_VOLUME_MAPPER; };
00146 
00149   virtual int IsARayCastMapper() {return 1;};
00150 
00153   virtual float GetGradientMagnitudeScale();
00154   virtual float GetGradientMagnitudeBias();
00155   
00156 
00157 
00158 protected:
00159   vtkVolumeRayCastMapper();
00160   ~vtkVolumeRayCastMapper();
00161   vtkVolumeRayCastMapper(const vtkVolumeRayCastMapper&) {};
00162   void operator=(const vtkVolumeRayCastMapper&) {};
00163 
00164   vtkVolumeRayCastFunction     *VolumeRayCastFunction;
00165   vtkEncodedGradientEstimator  *GradientEstimator;
00166   vtkEncodedGradientShader     *GradientShader;
00167 
00168   
00169   float                        SampleDistance;
00170 
00171   float                        WorldSampleDistance;
00172   int                          ScalarDataType;
00173   void                         *ScalarDataPointer;
00174   float                        *DepthRangeBufferPointer;
00175 
00176   int                          ClipRayAgainstVolume( 
00177                  VTKRayCastRayInfo *rayInfo,
00178                  VTKRayCastVolumeInfo *volumeInfo,
00179                  float bounds[6] );
00180 
00181   int                          ClipRayAgainstClippingPlanes( 
00182                  VTKRayCastRayInfo *rayInfo,
00183                  VTKRayCastVolumeInfo *volumeInfo,
00184                  vtkPlaneCollection *planes );
00185 
00186   void                         GeneralImageInitialization( vtkRenderer *ren, 
00187                         vtkVolume *vol );
00188 
00189   void                         UpdateShadingTables( vtkRenderer *ren, 
00190                       vtkVolume *vol );
00191 
00192   vtkRayBounder                *RayBounder;
00193 
00194   float                        RayStart[3];
00195   float                        RayEnd[3];
00196   int                          RayPixel[2];
00197   float                        RayColor[4];
00198   float                        VolumeBounds[6];
00199   float                        WorldToVolumeMatrix[16];
00200   float                        VolumeToWorldMatrix[16];
00201   float                        ViewToVolumeMatrix[16];
00202 };
00203 
00204 #endif
00205