Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
vtkMitkGPUVolumeRayCastMapper.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 /*=========================================================================
17 
18  Program: Visualization Toolkit
19  Module: $RCSfile: vtkMitkGPUVolumeRayCastMapper.h,v $
20 
21  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
22  All rights reserved.
23  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
24 
25  This software is distributed WITHOUT ANY WARRANTY; without even
26  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
27  PURPOSE. See the above copyright notice for more information.
28 
29 =========================================================================*/
30 // .NAME vtkMitkGPUVolumeRayCastMapper - Ray casting performed on the GPU.
31 // .SECTION Description
32 // vtkMitkGPUVolumeRayCastMapper is a volume mapper that performs ray casting on
33 // the GPU using fragment programs.
34 //
35 
36 #ifndef __vtkMitkGPUVolumeRayCastMapper_h
37 #define __vtkMitkGPUVolumeRayCastMapper_h
38 
39 #include "MitkMapperExtExports.h"
40 #include "mitkCommon.h"
41 #include "vtkVersionMacros.h"
42 #include "vtkVolumeMapper.h"
43 
44 // Only with VTK 5.6 or above
45 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
46 
47 class vtkVolumeProperty;
48 class vtkRenderWindow;
49 
50 // class vtkKWAMRVolumeMapper; // friend class.
51 
52 class MITKMAPPEREXT_EXPORT vtkMitkGPUVolumeRayCastMapper : public vtkVolumeMapper
53 {
54 public:
55  vtkTypeMacro(vtkMitkGPUVolumeRayCastMapper, vtkVolumeMapper);
56  void PrintSelf(ostream &os, vtkIndent indent) override;
57 
58  // Description:
59  // If AutoAdjustSampleDistances is on, the the ImageSampleDistance
60  // will be varied to achieve the allocated render time of this
61  // prop (controlled by the desired update rate and any culling in
62  // use).
63  vtkSetClampMacro(AutoAdjustSampleDistances, int, 0, 1);
64  vtkGetMacro(AutoAdjustSampleDistances, int);
65  vtkBooleanMacro(AutoAdjustSampleDistances, int);
66 
67  // Description:
68  // Set/Get the distance between samples used for rendering
69  // when AutoAdjustSampleDistances is off, or when this mapper
70  // has more than 1 second allocated to it for rendering.
71  // Initial value is 1.0.
72  vtkSetMacro(SampleDistance, float);
73  vtkGetMacro(SampleDistance, float);
74 
75  // Description:
76  // Sampling distance in the XY image dimensions. Default value of 1 meaning
77  // 1 ray cast per pixel. If set to 0.5, 4 rays will be cast per pixel. If
78  // set to 2.0, 1 ray will be cast for every 4 (2 by 2) pixels. This value
79  // will be adjusted to meet a desired frame rate when AutoAdjustSampleDistances
80  // is on.
81  vtkSetClampMacro(ImageSampleDistance, float, 0.1f, 100.0f);
82  vtkGetMacro(ImageSampleDistance, float);
83 
84  // Description:
85  // This is the minimum image sample distance allow when the image
86  // sample distance is being automatically adjusted.
87  vtkSetClampMacro(MinimumImageSampleDistance, float, 0.1f, 100.0f);
88  vtkGetMacro(MinimumImageSampleDistance, float);
89 
90  // Description:
91  // This is the maximum image sample distance allow when the image
92  // sample distance is being automatically adjusted.
93  vtkSetClampMacro(MaximumImageSampleDistance, float, 0.1f, 100.0f);
94  vtkGetMacro(MaximumImageSampleDistance, float);
95 
96  // Description:
97  // Set/Get the window / level applied to the final color.
98  // This allows brightness / contrast adjustments on the
99  // final image.
100  // window is the width of the window.
101  // level is the center of the window.
102  // Initial window value is 1.0
103  // Initial level value is 0.5
104  // window cannot be null but can be negative, this way
105  // values will be reversed.
106  // |window| can be larger than 1.0
107  // level can be any real value.
108  vtkSetMacro(FinalColorWindow, float);
109  vtkGetMacro(FinalColorWindow, float);
110  vtkSetMacro(FinalColorLevel, float);
111  vtkGetMacro(FinalColorLevel, float);
112 
113  // Description:
114  // Maximum size of the 3D texture in GPU memory.
115  // Will default to the size computed from the graphics
116  // card. Can be adjusted by the user.
117  vtkSetMacro(MaxMemoryInBytes, vtkIdType);
118  vtkGetMacro(MaxMemoryInBytes, vtkIdType);
119 
120  // Description:
121  // Maximum fraction of the MaxMemoryInBytes that should
122  // be used to hold the texture. Valid values are 0.1 to
123  // 1.0.
124  vtkSetClampMacro(MaxMemoryFraction, float, 0.1f, 1.0f);
125  vtkGetMacro(MaxMemoryFraction, float);
126 
127  // Description:
128  // Tells if the mapper will report intermediate progress.
129  // Initial value is true. As the progress works with a GL blocking
130  // call (glFinish()), this can be useful for huge dataset but can
131  // slow down rendering of small dataset. It should be set to true
132  // for big dataset or complex shading and streaming but to false for
133  // small datasets.
134  vtkSetMacro(ReportProgress, bool);
135  vtkGetMacro(ReportProgress, bool);
136 
137  // Description:
138  // Based on hardware and properties, we may or may not be able to
139  // render using 3D texture mapping. This indicates if 3D texture
140  // mapping is supported by the hardware, and if the other extensions
141  // necessary to support the specific properties are available.
142  virtual int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window), vtkVolumeProperty *vtkNotUsed(property))
143  {
144  return 0;
145  }
146 
147  void CreateCanonicalView(vtkRenderer *ren,
148  vtkVolume *volume,
149  vtkImageData *image,
150  int blend_mode,
151  double viewDirection[3],
152  double viewUp[3]);
153 
154  void SetMaskInput(vtkImageData *mask);
155  vtkGetObjectMacro(MaskInput, vtkImageData);
156 
157  // Description:
158  // Tells how much mask color transfer function is used compared to the
159  // standard color transfer function when the mask is true.
160  // 0.0 means only standard color transfer function.
161  // 1.0 means only mask color tranfer function.
162  // Initial value is 1.0.
163  vtkSetClampMacro(MaskBlendFactor, float, 0.0f, 1.0f);
164  vtkGetMacro(MaskBlendFactor, float);
165 
166  // BTX
167  // Description:
168  // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
169  // Initialize rendering for this volume.
170  void Render(vtkRenderer *, vtkVolume *) override;
171 
172  // Description:
173  // Handled in the subclass - the actual render method
174  // \pre input is up-to-date.
175  virtual void GPURender(vtkRenderer *, vtkVolume *) {}
176  // Description:
177  // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
178  // Release any graphics resources that are being consumed by this mapper.
179  // The parameter window could be used to determine which graphic
180  // resources to release.
181  // \deprecatedSince{2013_12}
182  DEPRECATED(void ReleaseGraphicsResources(vtkWindow *) override){};
183 
184  // Description:
185  // Return how much the dataset has to be reduced in each dimension to
186  // fit on the GPU. If the value is 1.0, there is no need to reduce the
187  // dataset.
188  // \pre the calling thread has a current OpenGL context.
189  // \pre mapper_supported: IsRenderSupported(renderer->GetRenderWindow(),0)
190  // The computation is based on hardware limits (3D texture indexable size)
191  // and MaxMemoryInBytes.
192  // \post valid_i_ratio: ratio[0]>0 && ratio[0]<=1.0
193  // \post valid_j_ratio: ratio[1]>0 && ratio[1]<=1.0
194  // \post valid_k_ratio: ratio[2]>0 && ratio[2]<=1.0
195  virtual void GetReductionRatio(double ratio[3]) = 0;
196 
197  // ETX
198 
199 protected:
200  vtkMitkGPUVolumeRayCastMapper();
201  ~vtkMitkGPUVolumeRayCastMapper();
202 
203  // Check to see that the render will be OK
204  int ValidateRender(vtkRenderer *, vtkVolume *);
205 
206  // Special version of render called during the creation
207  // of a canonical view.
208  void CanonicalViewRender(vtkRenderer *, vtkVolume *);
209 
210  // Methods called by the AMR Volume Mapper.
211  virtual void PreRender(vtkRenderer *ren,
212  vtkVolume *vol,
213  double datasetBounds[6],
214  double scalarRange[2],
215  int numberOfScalarComponents,
216  unsigned int numberOfLevels) = 0;
217 
218  // \pre input is up-to-date
219  virtual void RenderBlock(vtkRenderer *ren, vtkVolume *vol, unsigned int level) = 0;
220 
221  virtual void PostRender(vtkRenderer *ren, int numberOfScalarComponents) = 0;
222 
223  // Description:
224  // Called by the AMR Volume Mapper.
225  // Set the flag that tells if the scalars are on point data (0) or
226  // cell data (1).
227  void SetCellFlag(int cellFlag);
228 
229  // The distance between sample points along the ray
230  float SampleDistance;
231 
232  float ImageSampleDistance;
233  float MinimumImageSampleDistance;
234  float MaximumImageSampleDistance;
235  int AutoAdjustSampleDistances;
236 
237  int SmallVolumeRender;
238  double BigTimeToDraw;
239  double SmallTimeToDraw;
240 
241  float FinalColorWindow;
242  float FinalColorLevel;
243 
244  vtkIdType MaxMemoryInBytes;
245  float MaxMemoryFraction;
246 
247  // 1 if we are generating the canonical image, 0 otherwise
248  int GeneratingCanonicalView;
249  vtkImageData *CanonicalViewImageData;
250 
251  // Description:
252  // Set the mapper in AMR Mode or not. Initial value is false.
253  // Called only by the vtkKWAMRVolumeMapper
254  vtkSetClampMacro(AMRMode, int, 0, 1);
255  vtkGetMacro(AMRMode, int);
256  vtkBooleanMacro(AMRMode, int);
257 
258  int AMRMode;
259  int CellFlag; // point data or cell data (or field data, not handled) ?
260 
261  // Description:
262  // Compute the cropping planes clipped by the bounds of the volume.
263  // The result is put into this->ClippedCroppingRegionPlanes.
264  // NOTE: IT WILL BE MOVED UP TO vtkVolumeMapper after bullet proof usage
265  // in this mapper. Other subclasses will use the ClippedCroppingRegionsPlanes
266  // members instead of CroppingRegionPlanes.
267  // \pre volume_exists: this->GetInput()!=0
268  // \pre valid_cropping: this->Cropping &&
269  // this->CroppingRegionPlanes[0]<this->CroppingRegionPlanes[1] &&
270  // this->CroppingRegionPlanes[2]<this->CroppingRegionPlanes[3] &&
271  // this->CroppingRegionPlanes[4]<this->CroppingRegionPlanes[5])
272  virtual void ClipCroppingRegionPlanes();
273 
274  double ClippedCroppingRegionPlanes[6];
275 
276  bool ReportProgress;
277 
278  vtkImageData *MaskInput;
279 
280  float MaskBlendFactor;
281 
282  vtkGetObjectMacro(TransformedInput, vtkImageData);
283  void SetTransformedInput(vtkImageData *);
284 
285  vtkImageData *TransformedInput;
286 
287  // Description:
288  // This is needed only to check if the input data has been changed since the last
289  // Render() call.
290  vtkImageData *LastInput;
291 
292 private:
293  vtkMitkGPUVolumeRayCastMapper(const vtkMitkGPUVolumeRayCastMapper &); // Not implemented.
294  void operator=(const vtkMitkGPUVolumeRayCastMapper &); // Not implemented.
295 };
296 
297 #endif
298 
299 #endif
#define MITKMAPPEREXT_EXPORT
#define DEPRECATED(func)
Definition: mitkCommon.h:183