Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkGPUVolumeMapper3D.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 #ifndef MITKGPUVOLUMEMAPPER3D_H_HEADER_INCLUDED
18 #define MITKGPUVOLUMEMAPPER3D_H_HEADER_INCLUDED
19 
20 // MITK
21 #include "MitkMapperExtExports.h"
22 #include "mitkBaseRenderer.h"
23 #include "mitkCommon.h"
24 #include "mitkImage.h"
25 #include "mitkVtkMapper.h"
27 
28 // VTK
29 #include <vtkFixedPointVolumeRayCastMapper.h>
30 #include <vtkGPUVolumeRayCastMapper.h>
31 #include <vtkImageChangeInformation.h>
32 #include <vtkSmartPointer.h>
33 #include <vtkVersionMacros.h>
34 #include <vtkVolumeProperty.h>
35 
36 // Only with VTK 5.6 or above
37 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
38 
40 
41 #endif
42 
43 namespace mitk
44 {
45  /************************************************************************/
46  /* Properties that influence the mapper are:
47  *
48  * - \b "level window": for the level window of the volume data
49  * - \b "LookupTable" : for the lookup table of the volume data
50  * - \b "TransferFunction" (mitk::TransferFunctionProperty): for the used transfer function of the volume data
51  ************************************************************************/
52 
53  //##Documentation
54  //## @brief Vtk-based mapper for VolumeData
55  //##
56  //## @ingroup Mapper
58  {
59  public:
61 
62  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
63 
64  virtual const mitk::Image *GetInput();
65 
66  virtual vtkProp *GetVtkProp(mitk::BaseRenderer *renderer) override;
67 
68  virtual void ApplyProperties(vtkActor *actor, mitk::BaseRenderer *renderer) override;
69  static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer = NULL, bool overwrite = false);
70 
74  virtual bool IsLODEnabled(BaseRenderer *renderer = NULL) const override;
75  bool IsMIPEnabled(BaseRenderer *renderer = NULL);
76  bool IsGPUEnabled(BaseRenderer *renderer = NULL);
77  bool IsRAYEnabled(BaseRenderer *renderer = NULL);
78 
79  virtual void MitkRenderVolumetricGeometry(mitk::BaseRenderer *renderer) override;
80 
81  protected:
83  virtual ~GPUVolumeMapper3D();
84 
85  bool IsRenderable(mitk::BaseRenderer *renderer);
86 
87  void InitCommon();
88  void DeinitCommon();
89 
90  void InitCPU(mitk::BaseRenderer *renderer);
91  void DeinitCPU(mitk::BaseRenderer *renderer);
92  void GenerateDataCPU(mitk::BaseRenderer *renderer);
93 
94  bool InitGPU(mitk::BaseRenderer *renderer);
95  void DeinitGPU(mitk::BaseRenderer *renderer);
96  void GenerateDataGPU(mitk::BaseRenderer *renderer);
97 
98 // Only with VTK 5.6 or above
99 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
100 
101  bool InitRAY(mitk::BaseRenderer *renderer);
102  void DeinitRAY(mitk::BaseRenderer *renderer);
103  void GenerateDataRAY(mitk::BaseRenderer *renderer);
104 
105 #endif
106 
107  void InitVtkMapper(mitk::BaseRenderer *renderer);
108 
109  virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override;
110 
111  void CreateDefaultTransferFunctions();
112  void UpdateTransferFunctions(mitk::BaseRenderer *renderer);
113 
114  vtkSmartPointer<vtkVolume> m_VolumeNULL;
115 
117  vtkSmartPointer<vtkImageChangeInformation> m_UnitSpacingImageFilter;
118  vtkSmartPointer<vtkPiecewiseFunction> m_DefaultOpacityTransferFunction;
119  vtkSmartPointer<vtkPiecewiseFunction> m_DefaultGradientTransferFunction;
120  vtkSmartPointer<vtkColorTransferFunction> m_DefaultColorTransferFunction;
121  vtkSmartPointer<vtkPiecewiseFunction> m_BinaryOpacityTransferFunction;
122  vtkSmartPointer<vtkPiecewiseFunction> m_BinaryGradientTransferFunction;
123  vtkSmartPointer<vtkColorTransferFunction> m_BinaryColorTransferFunction;
124 
126  {
127  public:
128  // NO SMARTPOINTER HERE
129  vtkRenderWindow *m_VtkRenderWindow;
130 
132  vtkSmartPointer<vtkVolume> m_VolumeCPU;
133  vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> m_MapperCPU;
134  vtkSmartPointer<vtkVolumeProperty> m_VolumePropertyCPU;
135 
138  vtkSmartPointer<vtkVolume> m_VolumeGPU;
139  vtkSmartPointer<vtkMitkVolumeTextureMapper3D> m_MapperGPU;
140  vtkSmartPointer<vtkVolumeProperty> m_VolumePropertyGPU;
141 
142 // Only with VTK 5.6 or above
143 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
144 
145  bool m_raySupported;
146  bool m_rayInitialized;
147  vtkSmartPointer<vtkVolume> m_VolumeRAY;
148  vtkSmartPointer<vtkGPUVolumeRayCastMapper> m_MapperRAY;
149  vtkSmartPointer<vtkVolumeProperty> m_VolumePropertyRAY;
150 
151 #endif
152 
154  {
155  m_VtkRenderWindow = 0;
156 
157  m_cpuInitialized = false;
158 
159  m_gpuInitialized = false;
160  m_gpuSupported = true; // assume initially gpu slicing is supported
161 
162 // Only with VTK 5.6 or above
163 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
164  m_rayInitialized = false;
165  m_raySupported = true; // assume initially gpu raycasting is supported
166 #endif
167  }
168 
170  {
171  if (m_cpuInitialized && m_MapperCPU && m_VtkRenderWindow)
172  m_MapperCPU->ReleaseGraphicsResources(m_VtkRenderWindow);
173 
174  if (m_gpuInitialized && m_MapperGPU && m_VtkRenderWindow)
175  m_MapperGPU->ReleaseGraphicsResources(m_VtkRenderWindow);
176 
177 // Only with VTK 5.6 or above
178 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
179  if (m_rayInitialized && m_MapperRAY && m_VtkRenderWindow)
180  m_MapperRAY->ReleaseGraphicsResources(m_VtkRenderWindow);
181 #endif
182  }
183  };
184 
186  };
187 
188 } // namespace mitk
189 
190 #endif /* MITKVOLUMEDATAVTKMAPPER3D_H_HEADER_INCLUDED */
vtkSmartPointer< vtkImageChangeInformation > m_UnitSpacingImageFilter
vtkSmartPointer< vtkMitkVolumeTextureMapper3D > m_MapperGPU
Base class for mapper specific rendering ressources.
Definition: mitkMapper.h:200
#define MITKMAPPEREXT_EXPORT
vtkSmartPointer< vtkPiecewiseFunction > m_DefaultOpacityTransferFunction
vtkSmartPointer< vtkVolumeProperty > m_VolumePropertyGPU
Organizes the rendering process.
DataCollection - Class to facilitate loading/accessing structured data.
vtkSmartPointer< vtkVolume > m_VolumeGPU
Base class of all Vtk Mappers in order to display primitives by exploiting Vtk functionality.
Definition: mitkVtkMapper.h:53
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:54
vtkSmartPointer< vtkPiecewiseFunction > m_DefaultGradientTransferFunction
vtkSmartPointer< vtkVolumeProperty > m_VolumePropertyCPU
vtkSmartPointer< vtkPiecewiseFunction > m_BinaryOpacityTransferFunction
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Image class for storing images.
Definition: mitkImage.h:76
vtkSmartPointer< vtkVolume > m_VolumeNULL
mitk::LocalStorageHandler< LocalStorage > m_LSH
Vtk-based mapper for VolumeData.
vtkSmartPointer< vtkColorTransferFunction > m_DefaultColorTransferFunction
vtkSmartPointer< vtkVolume > m_VolumeCPU
vtkSmartPointer< vtkColorTransferFunction > m_BinaryColorTransferFunction
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
vtkSmartPointer< vtkPiecewiseFunction > m_BinaryGradientTransferFunction
vtkSmartPointer< vtkFixedPointVolumeRayCastMapper > m_MapperCPU