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