Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
vtkMitkVolumeTextureMapper3D.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 // .NAME vtkMitkVolumeTextureMapper3D - volume render with 3D texture mapping
18 
19 // .SECTION Description
20 // vtkMitkVolumeTextureMapper3D renders a volume using 3D texture mapping.
21 // This class is actually an abstract superclass - with all the actual
22 // work done by vtkMitkOpenGLVolumeTextureMapper3D.
23 //
24 // This mappers currently supports:
25 //
26 // - any data type as input
27 // - one component, or two or four non-independent components
28 // - composite blending
29 // - intermixed opaque geometry
30 // - multiple volumes can be rendered if they can
31 // be sorted into back-to-front order (use the vtkFrustumCoverageCuller)
32 //
33 // This mapper does not support:
34 // - more than one independent component
35 // - maximum intensity projection
36 //
37 // Internally, this mapper will potentially change the resolution of the
38 // input data. The data will be resampled to be a power of two in each
39 // direction, and also no greater than 128*256*256 voxels (any aspect)
40 // for one or two component data, or 128*128*256 voxels (any aspect)
41 // for four component data. The limits are currently hardcoded after
42 // a check using the GL_PROXY_TEXTURE3D because some graphics drivers
43 // were always responding "yes" to the proxy call despite not being
44 // able to allocate that much texture memory.
45 //
46 // Currently, calculations are computed using 8 bits per RGBA channel.
47 // In the future this should be expanded to handle newer boards that
48 // can support 15 bit float compositing.
49 //
50 // This mapper supports two main families of graphics hardware:
51 // nvidia and ATI. There are two different implementations of
52 // 3D texture mapping used - one based on nvidia's GL_NV_texture_shader2
53 // and GL_NV_register_combiners2 extension, and one based on
54 // ATI's GL_ATI_fragment_shader (supported also by some nvidia boards)
55 // To use this class in an application that will run on various
56 // hardware configurations, you should have a back-up volume rendering
57 // method. You should create a vtkMitkVolumeTextureMapper3D, assign its
58 // input, make sure you have a current OpenGL context (you've rendered
59 // at least once), then call IsRenderSupported with a vtkVolumeProperty
60 // as an argument. This method will return 0 if the input has more than
61 // one independent component, or if the graphics hardware does not
62 // support the set of required extensions for using at least one of
63 // the two implemented methods (nvidia or ati)
64 //
65 // .SECTION Thanks
66 // Thanks to Alexandre Gouaillard at the Megason Lab, Department of Systems
67 // Biology, Harvard Medical School
68 // https://wiki.med.harvard.edu/SysBio/Megason/
69 // for the idea and initial patch to speed-up rendering with compressed
70 // textures.
71 //
72 // .SECTION see also
73 // vtkVolumeMapper
74 
75 #ifndef __vtkMitkVolumeTextureMapper3D_h
76 #define __vtkMitkVolumeTextureMapper3D_h
77 
78 #include "MitkMapperExtExports.h"
79 #include "vtkVolumeMapper.h"
80 
81 class vtkImageData;
82 class vtkColorTransferFunction;
83 class vtkPiecewiseFunction;
84 class vtkVolumeProperty;
85 
86 #include "mitkCommon.h"
87 
88 class MITKMAPPEREXT_EXPORT vtkMitkVolumeTextureMapper3D : public vtkVolumeMapper
89 {
90 public:
91  vtkTypeMacro(vtkMitkVolumeTextureMapper3D, vtkVolumeMapper);
92  void PrintSelf(ostream &os, vtkIndent indent) override;
93 
94  // static vtkMitkVolumeTextureMapper3D *New(); //VTK6_TODO
95 
96  // Description:
97  // The distance at which to space sampling planes. This
98  // may not be honored for interactive renders. An interactive
99  // render is defined as one that has less than 1 second of
100  // allocated render time.
101  vtkSetMacro(SampleDistance, float);
102  vtkGetMacro(SampleDistance, float);
103 
104  // Description:
105  // These are the dimensions of the 3D texture
106  vtkGetVectorMacro(VolumeDimensions, int, 3);
107 
108  // Description:
109  // This is the spacing of the 3D texture
110  vtkGetVectorMacro(VolumeSpacing, float, 3);
111 
112  // Description:
113  // Based on hardware and properties, we may or may not be able to
114  // render using 3D texture mapping. This indicates if 3D texture
115  // mapping is supported by the hardware, and if the other extensions
116  // necessary to support the specific properties are available.
117  virtual int IsRenderSupported(vtkRenderer *, vtkVolumeProperty *) = 0;
118 
119  // Description:
120  // Allow access to the number of polygons used for the
121  // rendering.
122  vtkGetMacro(NumberOfPolygons, int);
123 
124  // Description:
125  // Allow access to the actual sample distance used to render
126  // the image.
127  vtkGetMacro(ActualSampleDistance, float);
128 
129  // BTX
130 
131  // Description:
132  // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
133  // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
134  // Render the volume
135  virtual void Render(vtkRenderer *, vtkVolume *) override{};
136 
137  // Description:
138  // Set/Get if the mapper use compressed textures (if supported by the
139  // hardware). Initial value is false.
140  // There are two reasons to use compressed textures: 1. rendering can be 4
141  // times faster. 2. It saves some VRAM.
142  // There is one reason to not use compressed textures: quality may be lower
143  // than with uncompressed textures.
144  vtkSetMacro(UseCompressedTexture, bool);
145  vtkGetMacro(UseCompressedTexture, bool);
146 
147  void UpdateMTime();
148 
149 protected:
152 
157 
158  /*
159  unsigned char *Volume1;
160  unsigned char *Volume2;
161  unsigned char *Volume3;
162  */
163  /*
164  int VolumeSize;
165  int VolumeComponents;
166  */
167 
168  int VolumeDimensions[3];
169  float VolumeSpacing[3];
170 
173 
174  vtkImageData *SavedTextureInput;
175  vtkImageData *SavedParametersInput;
176 
177  vtkColorTransferFunction *SavedRGBFunction;
178  vtkPiecewiseFunction *SavedGrayFunction;
179  vtkPiecewiseFunction *SavedScalarOpacityFunction;
180  vtkPiecewiseFunction *SavedGradientOpacityFunction;
184 
185  unsigned char ColorLookup[65536 * 4];
186  unsigned char AlphaLookup[65536];
187  float TempArray1[3 * 4096];
188  float TempArray2[4096];
192 
193  unsigned char DiffuseLookup[65536 * 4];
194  unsigned char SpecularLookup[65536 * 4];
195 
196  vtkTimeStamp SavedTextureMTime;
197  vtkTimeStamp SavedParametersMTime;
198 
200 
202 
203  // Description:
204  // For the given viewing direction, compute the set of polygons.
205  void ComputePolygons(vtkRenderer *ren, vtkVolume *vol, double bounds[6]);
206 
207  // Description:
208  // Update the internal RGBA representation of the volume. Return 1 if
209  // anything change, 0 if nothing changed.
210  int UpdateColorLookup(vtkVolume *);
211 
212  // Description:
213  // Impemented in subclass - check is texture size is OK.
214  // BTX
215  virtual int IsTextureSizeSupported(int vtkNotUsed(size)[3], int vtkNotUsed(components)) { return 0; }
216  // ETX
217 
218 private:
219  vtkMitkVolumeTextureMapper3D(const vtkMitkVolumeTextureMapper3D &); // Not implemented.
220  void operator=(const vtkMitkVolumeTextureMapper3D &); // Not implemented.
221 };
222 
223 #endif
#define MITKMAPPEREXT_EXPORT
virtual void Render(vtkRenderer *, vtkVolume *) override
vtkColorTransferFunction * SavedRGBFunction
virtual int IsTextureSizeSupported(int vtkNotUsed(size)[3], int vtkNotUsed(components))
vtkPiecewiseFunction * SavedGradientOpacityFunction
vtkPiecewiseFunction * SavedScalarOpacityFunction