1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkUnstructuredGridVolumeRayCastMapper.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 16 // .NAME vtkUnstructuredGridVolumeRayCastMapper - A software mapper for unstructured volumes 17 // .SECTION Description 18 // This is a software ray caster for rendering volumes in vtkUnstructuredGrid. 19 20 // .SECTION see also 21 // vtkVolumeMapper 22 23 #ifndef vtkUnstructuredGridVolumeRayCastMapper_h 24 #define vtkUnstructuredGridVolumeRayCastMapper_h 25 26 #include "vtkRenderingVolumeModule.h" // For export macro 27 #include "vtkUnstructuredGridVolumeMapper.h" 28 29 class vtkDoubleArray; 30 class vtkIdList; 31 class vtkMultiThreader; 32 class vtkRayCastImageDisplayHelper; 33 class vtkRenderer; 34 class vtkTimerLog; 35 class vtkUnstructuredGridVolumeRayCastFunction; 36 class vtkUnstructuredGridVolumeRayCastIterator; 37 class vtkUnstructuredGridVolumeRayIntegrator; 38 class vtkVolume; 39 40 class VTKRENDERINGVOLUME_EXPORT vtkUnstructuredGridVolumeRayCastMapper : public vtkUnstructuredGridVolumeMapper 41 { 42 public: 43 static vtkUnstructuredGridVolumeRayCastMapper *New(); 44 vtkTypeMacro(vtkUnstructuredGridVolumeRayCastMapper,vtkUnstructuredGridVolumeMapper); 45 void PrintSelf( ostream& os, vtkIndent indent ); 46 47 // Description: 48 // Sampling distance in the XY image dimensions. Default value of 1 meaning 49 // 1 ray cast per pixel. If set to 0.5, 4 rays will be cast per pixel. If 50 // set to 2.0, 1 ray will be cast for every 4 (2 by 2) pixels. 51 vtkSetClampMacro( ImageSampleDistance, float, 0.1f, 100.0f ); 52 vtkGetMacro( ImageSampleDistance, float ); 53 54 // Description: 55 // This is the minimum image sample distance allow when the image 56 // sample distance is being automatically adjusted 57 vtkSetClampMacro( MinimumImageSampleDistance, float, 0.1f, 100.0f ); 58 vtkGetMacro( MinimumImageSampleDistance, float ); 59 60 // Description: 61 // This is the maximum image sample distance allow when the image 62 // sample distance is being automatically adjusted 63 vtkSetClampMacro( MaximumImageSampleDistance, float, 0.1f, 100.0f ); 64 vtkGetMacro( MaximumImageSampleDistance, float ); 65 66 // Description: 67 // If AutoAdjustSampleDistances is on, the the ImageSampleDistance 68 // will be varied to achieve the allocated render time of this 69 // prop (controlled by the desired update rate and any culling in 70 // use). 71 vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 ); 72 vtkGetMacro( AutoAdjustSampleDistances, int ); 73 vtkBooleanMacro( AutoAdjustSampleDistances, int ); 74 75 // Description: 76 // Set/Get the number of threads to use. This by default is equal to 77 // the number of available processors detected. 78 vtkSetMacro( NumberOfThreads, int ); 79 vtkGetMacro( NumberOfThreads, int ); 80 81 // Description: 82 // If IntermixIntersectingGeometry is turned on, the zbuffer will be 83 // captured and used to limit the traversal of the rays. 84 vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 ); 85 vtkGetMacro( IntermixIntersectingGeometry, int ); 86 vtkBooleanMacro( IntermixIntersectingGeometry, int ); 87 88 // Description: 89 // Set/Get the helper class for casting rays. 90 virtual void SetRayCastFunction(vtkUnstructuredGridVolumeRayCastFunction *f); 91 vtkGetObjectMacro(RayCastFunction, vtkUnstructuredGridVolumeRayCastFunction); 92 93 // Description: 94 // Set/Get the helper class for integrating rays. If set to NULL, a 95 // default integrator will be assigned. 96 virtual void SetRayIntegrator(vtkUnstructuredGridVolumeRayIntegrator *ri); 97 vtkGetObjectMacro(RayIntegrator, vtkUnstructuredGridVolumeRayIntegrator); 98 99 //BTX 100 // Description: 101 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 102 // Initialize rendering for this volume. 103 void Render( vtkRenderer *, vtkVolume * ); 104 105 // Description: 106 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 107 // Release any graphics resources that are being consumed by this mapper. 108 // The parameter window could be used to determine which graphic 109 // resources to release. 110 void ReleaseGraphicsResources(vtkWindow *); 111 112 vtkGetVectorMacro( ImageInUseSize, int, 2 ); 113 vtkGetVectorMacro( ImageOrigin, int, 2 ); 114 vtkGetVectorMacro( ImageViewportSize, int , 2 ); 115 116 //ETX 117 118 void CastRays( int threadID, int threadCount ); 119 120 protected: 121 vtkUnstructuredGridVolumeRayCastMapper(); 122 ~vtkUnstructuredGridVolumeRayCastMapper(); 123 124 float ImageSampleDistance; 125 float MinimumImageSampleDistance; 126 float MaximumImageSampleDistance; 127 int AutoAdjustSampleDistances; 128 129 vtkMultiThreader *Threader; 130 int NumberOfThreads; 131 132 vtkRayCastImageDisplayHelper *ImageDisplayHelper; 133 134 // This is how big the image would be if it covered the entire viewport 135 int ImageViewportSize[2]; 136 137 // This is how big the allocated memory for image is. This may be bigger 138 // or smaller than ImageFullSize - it will be bigger if necessary to 139 // ensure a power of 2, it will be smaller if the volume only covers a 140 // small region of the viewport 141 int ImageMemorySize[2]; 142 143 // This is the size of subregion in ImageSize image that we are using for 144 // the current image. Since ImageSize is a power of 2, there is likely 145 // wasted space in it. This number will be used for things such as clearing 146 // the image if necessary. 147 int ImageInUseSize[2]; 148 149 // This is the location in ImageFullSize image where our ImageSize image 150 // is located. 151 int ImageOrigin[2]; 152 153 // This is the allocated image 154 unsigned char *Image; 155 156 float *RenderTimeTable; 157 vtkVolume **RenderVolumeTable; 158 vtkRenderer **RenderRendererTable; 159 int RenderTableSize; 160 int RenderTableEntries; 161 162 void StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t ); 163 float RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol ); 164 165 int IntermixIntersectingGeometry; 166 167 float *ZBuffer; 168 int ZBufferSize[2]; 169 int ZBufferOrigin[2]; 170 171 // Get the ZBuffer value corresponding to location (x,y) where (x,y) 172 // are indexing into the ImageInUse image. This must be converted to 173 // the zbuffer image coordinates. Nearest neighbor value is returned. 174 double GetZBufferValue( int x, int y ); 175 176 double GetMinimumBoundsDepth( vtkRenderer *ren, 177 vtkVolume *vol ); 178 179 vtkUnstructuredGridVolumeRayCastFunction *RayCastFunction; 180 vtkUnstructuredGridVolumeRayCastIterator **RayCastIterators; 181 vtkUnstructuredGridVolumeRayIntegrator *RayIntegrator; 182 vtkUnstructuredGridVolumeRayIntegrator *RealRayIntegrator; 183 184 vtkIdList **IntersectedCellsBuffer; 185 vtkDoubleArray **IntersectionLengthsBuffer; 186 vtkDataArray **NearIntersectionsBuffer; 187 vtkDataArray **FarIntersectionsBuffer; 188 189 vtkVolume *CurrentVolume; 190 vtkRenderer *CurrentRenderer; 191 192 vtkDataArray *Scalars; 193 int CellScalars; 194 195 private: 196 vtkUnstructuredGridVolumeRayCastMapper(const vtkUnstructuredGridVolumeRayCastMapper&); // Not implemented. 197 void operator=(const vtkUnstructuredGridVolumeRayCastMapper&); // Not implemented. 198 }; 199 200 #endif 201 202