VTK
vtkVolumeTexture.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkVolumeTexture.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 
62 #ifndef vtkVolumeTexture_h
63 #define vtkVolumeTexture_h
64 
65 #include <map> // For ImageDataBlockMap
66 #include <vector> // For ImageDataBlocks
67 
68 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
69 #include "vtkObject.h"
70 #include "vtkTimeStamp.h" // For UploadTime
71 #include "vtkTuple.h" // For Size6 and Size3
72 
73 
74 class vtkDataArray;
75 class vtkImageData;
76 class vtkMatrix4x4;
78 class vtkRenderer;
79 class vtkTextureObject;
80 class vtkWindow;
81 
82 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkVolumeTexture : public vtkObject
83 {
84  typedef vtkTuple<int, 6> Size6;
85  typedef vtkTuple<int, 3> Size3;
86 
87 public:
88  static vtkVolumeTexture* New();
89 
90  struct VolumeBlock
91  {
92  VolumeBlock(vtkImageData* imData, vtkTextureObject* tex, Size3 const& texSize)
93  {
94  // Block extent is stored in vtkImageData
95  ImageData = imData;
96  TextureObject = tex;
97  TextureSize = texSize;
98  TupleIndex = 0;
99  }
100 
105  };
106 
107  vtkTypeMacro(vtkVolumeTexture, vtkObject);
108  void PrintSelf( ostream& os, vtkIndent indent ) override;
109 
113  void SetMapper(vtkOpenGLGPUVolumeRayCastMapper* mapper);
114 
118  void SetPartitions(int const x, int const y, int const z);
119  const Size3& GetPartitions();
120 
127  bool LoadVolume(vtkRenderer* ren, vtkImageData* data, vtkDataArray* scalars,
128  int const interpolation);
129 
130  void UpdateInterpolationType(int const interpolation);
131 
136  void SortBlocksBackToFront(vtkRenderer *ren, vtkMatrix4x4* volumeMat);
137 
143  VolumeBlock* GetNextBlock();
144 
148  void ReleaseGraphicsResources(vtkWindow* win);
149 
156  static void GetScaleAndBias(const int scalarType, double * scalarRange,
157  float& scale, float& bias);
158 
159  //----------------------------------------------------------------------------
160 
162  float Scale[4];
163  float Bias[4];
164  double ScalarRange[4][2];
167 
168 protected:
170  ~vtkVolumeTexture() override;
171 
172 private:
177  bool LoadTexture(int const interpolation, VolumeBlock* volBlock);
178 
182  void SplitVolume(vtkImageData* imageData, Size3 const & part);
183 
187  void SetInterpolation(int const interpolation);
188 
189  void CreateBlocks(unsigned int const format, unsigned int const internalFormat,
190  int const type);
191 
192  void AdjustExtentForCell(Size6& extent);
193  Size3 ComputeBlockSize(int* extent);
194 
199  void SelectTextureFormat(unsigned int& format, unsigned int& internalFormat,
200  int& type, int const scalarType, int const noOfComponents);
201 
205  void ClearBlocks();
206 
207  vtkVolumeTexture(const vtkVolumeTexture&) = delete;
208  void operator=(const vtkVolumeTexture&) = delete;
209 
211 
219  bool AreDimensionsValid(vtkTextureObject* texture, int const width,
220  int const height, int const depth);
221 
222  bool SafeLoadTexture(vtkTextureObject* texture, int const width,
223  int const height, int const depth, int numComps, int dataType, void* dataPtr);
225 
226  //----------------------------------------------------------------------------
227  vtkTextureObject* Texture;
228  std::vector<vtkImageData*> ImageDataBlocks;
229  std::map<vtkImageData*, VolumeBlock*> ImageDataBlockMap;
230  std::vector<VolumeBlock*> SortedVolumeBlocks;
231  size_t CurrentBlockIdx;
232  bool StreamBlocks;
233 
234  std::vector<Size3> TextureSizes;
235  Size6 FullExtent;
236  Size3 FullSize;
237  Size3 FullSizeAdjusted; /* Cell Adjusted */
238  Size3 Partitions;
239 
240  vtkDataArray* Scalars;
242 };
243 
244 #endif //vtkVolumeTexture_h
abstract base class for most VTK objects
Definition: vtkObject.h:59
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Creates and manages the volume texture rendered by vtkOpenGLGPUVolumeRayCastMapper.
record modification and/or execution time
Definition: vtkTimeStamp.h:35
abstract specification for renderers
Definition: vtkRenderer.h:63
int vtkIdType
Definition: vtkType.h:345
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
OpenGL subclass that draws the image to the screen.
vtkTextureObject * TextureObject
a simple class to control print indentation
Definition: vtkIndent.h:39
VolumeBlock(vtkImageData *imData, vtkTextureObject *tex, Size3 const &texSize)
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
abstracts an OpenGL texture object.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkTimeStamp UploadTime