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 
66 #ifndef vtkVolumeTexture_h
67 #define vtkVolumeTexture_h
68 #include <map> // For ImageDataBlockMap
69 #include <vector> // For ImageDataBlocks
70 
71 #include "vtkMatrix4x4.h" // For vtkMatrix4
72 #include "vtkNew.h" // For vtkNew
73 #include "vtkObject.h"
74 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
75 #include "vtkSmartPointer.h" // For SmartPointer
76 #include "vtkTimeStamp.h" // For UploadTime
77 #include "vtkTuple.h" // For Size6 and Size3
78 
79 
80 class vtkDataArray;
81 class vtkImageData;
82 class vtkVolumeProperty;
83 class vtkRenderer;
84 class vtkTextureObject;
85 class vtkWindow;
86 
87 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkVolumeTexture : public vtkObject
88 {
89  typedef vtkTuple<int, 6> Size6;
90  typedef vtkTuple<int, 3> Size3;
91 
92 public:
93  static vtkVolumeTexture* New();
94 
95  struct VolumeBlock
96  {
97  VolumeBlock(vtkImageData* imData, vtkTextureObject* tex, Size3 const& texSize)
98  {
99  // Block extent is stored in vtkImageData
100  ImageData = imData;
101  TextureObject = tex;
102  TextureSize = texSize;
103  TupleIndex = 0;
104 
105  this->Extents[0] = VTK_INT_MAX;
106  this->Extents[1] = VTK_INT_MIN;
107  this->Extents[2] = VTK_INT_MAX;
108  this->Extents[3] = VTK_INT_MIN;
109  this->Extents[4] = VTK_INT_MAX;
110  this->Extents[5] = VTK_INT_MIN;
111  }
112 
115  Size3 TextureSize;
119 
120  double CellScale[3];
121  float CellStep[3];
122  double DatasetStepSize[3];
123 
128  double LoadedBounds[6];
129  int Extents[6];
130  };
131 
132  vtkTypeMacro(vtkVolumeTexture, vtkObject);
133  void PrintSelf( ostream& os, vtkIndent indent ) override;
134 
138  void SetPartitions(int const x, int const y, int const z);
139  const Size3& GetPartitions();
140 
147  bool LoadVolume(vtkRenderer* ren, vtkImageData* data, vtkDataArray* scalars,
148  int const isCell, int const interpolation);
149 
154  void UpdateVolume(vtkVolumeProperty* property);
155 
160  void SortBlocksBackToFront(vtkRenderer *ren, vtkMatrix4x4* volumeMat);
161 
166  VolumeBlock* GetNextBlock();
170  VolumeBlock* GetCurrentBlock();
171 
175  void ReleaseGraphicsResources(vtkWindow* win);
176 
183  static void GetScaleAndBias(const int scalarType, float* scalarRange,
184  float& scale, float& bias);
185  vtkDataArray* GetLoadedScalars();
186 
188  float Scale[4];
189  float Bias[4];
190  float ScalarRange[4][2];
191  float CellSpacing[3];
194 
195  int IsCellData = 0;
197  float AdjustedTexMin[4];
198  float AdjustedTexMax[4];
199 
200 protected:
202  ~vtkVolumeTexture() override;
203 
204 private:
205  vtkVolumeTexture(const vtkVolumeTexture&) = delete;
206  void operator=(const vtkVolumeTexture&) = delete;
207 
212  bool LoadTexture(int const interpolation, VolumeBlock* volBlock);
213 
217  void SplitVolume(vtkImageData* imageData, Size3 const & part);
218 
219  void CreateBlocks(unsigned int const format, unsigned int const internalFormat,
220  int const type);
221 
222  void AdjustExtentForCell(Size6& extent);
223  Size3 ComputeBlockSize(int* extent);
224 
229  void SelectTextureFormat(unsigned int& format, unsigned int& internalFormat,
230  int& type, int const scalarType, int const noOfComponents);
231 
235  void ClearBlocks();
236 
240  void ComputeBounds(VolumeBlock* block);
241  void UpdateTextureToDataMatrix(VolumeBlock* block);
242 
261  void ComputeCellToPointMatrix(int extents[6]);
262 
264 
272  bool AreDimensionsValid(vtkTextureObject* texture, int const width,
273  int const height, int const depth);
274 
275  bool SafeLoadTexture(vtkTextureObject* texture, int const width,
276  int const height, int const depth, int numComps, int dataType, void* dataPtr);
278 
279  void UpdateInterpolationType(int const interpolation);
280  void SetInterpolation(int const interpolation);
281 
282 
283  //----------------------------------------------------------------------------
284  vtkTimeStamp UpdateTime;
285 
287  std::vector<vtkImageData*> ImageDataBlocks;
288  std::map<vtkImageData*, VolumeBlock*> ImageDataBlockMap;
289  std::vector<VolumeBlock*> SortedVolumeBlocks;
290  size_t CurrentBlockIdx;
291  bool StreamBlocks;
292 
293  std::vector<Size3> TextureSizes;
294  Size6 FullExtent;
295  Size3 FullSize;
296  Size3 Partitions;
297 
298  vtkDataArray* Scalars;
299 };
300 
301 #endif //vtkVolumeTexture_h
abstract base class for most VTK objects
Definition: vtkObject.h:59
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
Creates and manages the volume texture rendered by vtkOpenGLGPUVolumeRayCastMapper.
#define VTK_INT_MAX
Definition: vtkType.h:159
record modification and/or execution time
Definition: vtkTimeStamp.h:35
abstract specification for renderers
Definition: vtkRenderer.h:63
int vtkIdType
Definition: vtkType.h:347
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
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
represents the common properties for rendering a volume.
vtkNew< vtkMatrix4x4 > TextureToDataset
abstracts an OpenGL texture object.
vtkNew< vtkMatrix4x4 > TextureToDatasetInv
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkNew< vtkMatrix4x4 > CellToPointMatrix
vtkTimeStamp UploadTime
#define VTK_INT_MIN
Definition: vtkType.h:158