1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkImageResliceMapper.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 // .NAME vtkImageResliceMapper - map a slice of a vtkImageData to the screen 16 // .SECTION Description 17 // vtkImageResliceMapper will cut a 3D image with an abitrary slice plane 18 // and draw the results on the screen. The slice can be set to automatically 19 // follow the camera, so that the camera controls the slicing. 20 // .SECTION Thanks 21 // Thanks to David Gobbi at the Seaman Family MR Centre and Dept. of Clinical 22 // Neurosciences, Foothills Medical Centre, Calgary, for providing this class. 23 // .SECTION See also 24 // vtkImageSlice vtkImageProperty vtkImageSliceMapper 25 26 #ifndef vtkImageResliceMapper_h 27 #define vtkImageResliceMapper_h 28 29 #include "vtkRenderingImageModule.h" // For export macro 30 #include "vtkImageMapper3D.h" 31 32 class vtkImageSliceMapper; 33 class vtkRenderer; 34 class vtkRenderWindow; 35 class vtkCamera; 36 class vtkLookupTable; 37 class vtkImageSlice; 38 class vtkImageData; 39 class vtkImageResliceToColors; 40 class vtkMatrix4x4; 41 class vtkAbstractImageInterpolator; 42 43 class VTKRENDERINGIMAGE_EXPORT vtkImageResliceMapper : public vtkImageMapper3D 44 { 45 public: 46 static vtkImageResliceMapper *New(); 47 vtkTypeMacro(vtkImageResliceMapper,vtkImageMapper3D); 48 void PrintSelf(ostream& os, vtkIndent indent); 49 50 // Description: 51 // Set the slice that will be used to cut through the image. 52 // This slice should be in world coordinates, rather than 53 // data coordinates. Use SliceFacesCamera and SliceAtFocalPoint 54 // if you want the slice to automatically follow the camera. 55 virtual void SetSlicePlane(vtkPlane *plane); 56 57 // Description: 58 // When using SliceAtFocalPoint, this causes the slicing to occur at 59 // the closest slice to the focal point, instead of the default behavior 60 // where a new slice is interpolated between the original slices. This 61 // flag is ignored if the slicing is oblique to the original slices. 62 vtkSetMacro(JumpToNearestSlice, int); 63 vtkBooleanMacro(JumpToNearestSlice, int); 64 vtkGetMacro(JumpToNearestSlice, int); 65 66 // Description: 67 // The slab thickness, for thick slicing (default: zero) 68 vtkSetMacro(SlabThickness, double); 69 vtkGetMacro(SlabThickness, double); 70 71 // Description: 72 // The slab type, for thick slicing (default: Mean). 73 // The resulting view is a parallel projection through the volume. This 74 // method can be used to generate a facsimile of a digitally-reconstructed 75 // radiograph or a minimum-intensity projection as long as perspective 76 // geometry is not required. Note that the Sum mode provides an output 77 // with units of intensity times distance, while all other modes provide 78 // an output with units of intensity. 79 vtkSetClampMacro(SlabType, int, VTK_IMAGE_SLAB_MIN, VTK_IMAGE_SLAB_SUM); 80 vtkGetMacro(SlabType, int); SetSlabTypeToMin()81 void SetSlabTypeToMin() { 82 this->SetSlabType(VTK_IMAGE_SLAB_MIN); }; SetSlabTypeToMax()83 void SetSlabTypeToMax() { 84 this->SetSlabType(VTK_IMAGE_SLAB_MAX); }; SetSlabTypeToMean()85 void SetSlabTypeToMean() { 86 this->SetSlabType(VTK_IMAGE_SLAB_MEAN); }; SetSlabTypeToSum()87 void SetSlabTypeToSum() { 88 this->SetSlabType(VTK_IMAGE_SLAB_SUM); }; 89 virtual const char *GetSlabTypeAsString(); 90 91 // Description: 92 // Set the number of slab samples to use as a factor of the number 93 // of input slices within the slab thickness. The default value 94 // is 2, but 1 will increase speed with very little loss of quality. 95 vtkSetClampMacro(SlabSampleFactor, int, 1, 2); 96 vtkGetMacro(SlabSampleFactor, int); 97 98 // Description: 99 // Set the reslice sample frequency as in relation to the input image 100 // sample frequency. The default value is 1, but higher values can be 101 // used to improve the results. This is cheaper than turning on 102 // ResampleToScreenPixels. 103 vtkSetClampMacro(ImageSampleFactor, int, 1, 16); 104 vtkGetMacro(ImageSampleFactor, int); 105 106 // Description: 107 // Automatically reduce the rendering quality for greater speed 108 // when doing an interactive render. This is on by default. 109 vtkSetMacro(AutoAdjustImageQuality, int); 110 vtkBooleanMacro(AutoAdjustImageQuality, int); 111 vtkGetMacro(AutoAdjustImageQuality, int); 112 113 // Description: 114 // Resample the image directly to the screen pixels, instead of 115 // using a texture to scale the image after resampling. This is 116 // slower and uses more memory, but provides high-quality results. 117 // It is On by default. 118 vtkSetMacro(ResampleToScreenPixels, int); 119 vtkBooleanMacro(ResampleToScreenPixels, int); 120 vtkGetMacro(ResampleToScreenPixels, int); 121 122 // Description: 123 // Keep the color mapping stage distinct from the reslicing stage. 124 // This will improve the quality and possibly the speed of interactive 125 // window/level operations, but it uses more memory and might slow down 126 // interactive slicing operations. On by default. 127 vtkSetMacro(SeparateWindowLevelOperation, int); 128 vtkBooleanMacro(SeparateWindowLevelOperation, int); 129 vtkGetMacro(SeparateWindowLevelOperation, int); 130 131 // Description: 132 // Set a custom interpolator. This will only be used if the 133 // ResampleToScreenPixels option is on. 134 virtual void SetInterpolator(vtkAbstractImageInterpolator *sampler); 135 virtual vtkAbstractImageInterpolator *GetInterpolator(); 136 137 // Description: 138 // This should only be called by the renderer. 139 virtual void Render(vtkRenderer *renderer, vtkImageSlice *prop); 140 141 // Description: 142 // Release any graphics resources that are being consumed by 143 // this mapper. The parameter window is used to determine 144 // which graphic resources to release. 145 virtual void ReleaseGraphicsResources(vtkWindow *); 146 147 // Description: 148 // Get the mtime for the mapper. 149 unsigned long GetMTime(); 150 151 // Description: 152 // The bounding box (array of six doubles) of the data expressed as 153 // (xmin,xmax, ymin,ymax, zmin,zmax). 154 double *GetBounds(); GetBounds(double bounds[6])155 void GetBounds(double bounds[6]) 156 { this->vtkAbstractMapper3D::GetBounds(bounds); }; 157 158 // Description: 159 // Handle requests from the pipeline executive. 160 int ProcessRequest(vtkInformation* request, 161 vtkInformationVector** inInfo, 162 vtkInformationVector* outInfo); 163 164 protected: 165 vtkImageResliceMapper(); 166 ~vtkImageResliceMapper(); 167 168 // Description: 169 // Do a checkerboard pattern to the alpha of an RGBA image 170 void CheckerboardImage( 171 vtkImageData *input, vtkCamera *camera, vtkImageProperty *property); 172 173 // Description: 174 // Update the slice-to-world matrix from the camera. 175 void UpdateSliceToWorldMatrix(vtkCamera *camera); 176 177 // Description: 178 // Check if the vtkProp3D matrix has changed, and if so, set 179 // the WorldToDataMatrix to its inverse. 180 void UpdateWorldToDataMatrix(vtkImageSlice *prop); 181 182 // Description: 183 // Update the reslice matrix, which is the slice-to-data matrix. 184 void UpdateResliceMatrix(vtkRenderer *ren, vtkImageSlice *prop); 185 186 // Description: 187 // Set all of the reslicing parameters. This requires that 188 // the SliceToWorld and WorldToData matrices are up-to-date. 189 void UpdateResliceInformation(vtkRenderer *ren); 190 191 // Description: 192 // Set the interpolation. 193 void UpdateResliceInterpolation(vtkImageProperty *property); 194 195 // Description: 196 // Update anything related to the image coloring. 197 void UpdateColorInformation(vtkImageProperty *property); 198 199 // Description: 200 // Make a polygon by cutting the data bounds with a plane. 201 void UpdatePolygonCoords(vtkRenderer *ren); 202 203 // Description: 204 // Override Update to handle some tricky details. 205 void Update(); 206 void Update(int port); 207 208 // Description: 209 // Garbage collection for reference loops. 210 void ReportReferences(vtkGarbageCollector*); 211 212 vtkImageSliceMapper *SliceMapper; // Does the OpenGL rendering 213 214 int JumpToNearestSlice; // Adjust SliceAtFocalPoint 215 int AutoAdjustImageQuality; // LOD-style behavior 216 int SeparateWindowLevelOperation; // Do window/level as a separate step 217 double SlabThickness; // Current slab thickness 218 int SlabType; // Current slab mode 219 int SlabSampleFactor; // Sampling factor for slab mode 220 int ImageSampleFactor; // Sampling factor for image pixels 221 int ResampleToScreenPixels; // Use software interpolation only 222 int InternalResampleToScreenPixels; // Use software interpolation only 223 int ResliceNeedUpdate; // Execute reslice on next render 224 vtkImageResliceToColors *ImageReslice; // For software interpolation 225 vtkMatrix4x4 *ResliceMatrix; // Cached reslice matrix 226 vtkMatrix4x4 *WorldToDataMatrix; // World to Data transform matrix 227 vtkMatrix4x4 *SliceToWorldMatrix; // Slice to World transform matrix 228 vtkTimeStamp UpdateTime; 229 230 private: 231 vtkImageResliceMapper(const vtkImageResliceMapper&); // Not implemented. 232 void operator=(const vtkImageResliceMapper&); // Not implemented. 233 }; 234 235 #endif 236