VTK  9.0.1
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 
65 #ifndef vtkVolumeTexture_h
66 #define vtkVolumeTexture_h
67 #include <map> // For ImageDataBlockMap
68 #include <vector> // For ImageDataBlocks
69 
70 #include "vtkMatrix4x4.h" // For vtkMatrix4
71 #include "vtkNew.h" // For vtkNew
72 #include "vtkObject.h"
73 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
74 #include "vtkSmartPointer.h" // For SmartPointer
75 #include "vtkTimeStamp.h" // For UploadTime
76 #include "vtkTuple.h" // For Size6 and Size3
77 
78 class vtkDataArray;
79 class vtkImageData;
80 class vtkVolumeProperty;
81 class vtkRenderer;
82 class vtkTextureObject;
83 class vtkWindow;
84 
85 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkVolumeTexture : public vtkObject
86 {
87  typedef vtkTuple<int, 6> Size6;
88  typedef vtkTuple<int, 3> Size3;
89 
90 public:
91  static vtkVolumeTexture* New();
92 
93  struct VolumeBlock
94  {
95  VolumeBlock(vtkImageData* imData, vtkTextureObject* tex, Size3 const& texSize)
96  {
97  // Block extent is stored in vtkImageData
98  ImageData = imData;
99  TextureObject = tex;
100  TextureSize = texSize;
101  TupleIndex = 0;
102 
103  this->Extents[0] = VTK_INT_MAX;
104  this->Extents[1] = VTK_INT_MIN;
105  this->Extents[2] = VTK_INT_MAX;
106  this->Extents[3] = VTK_INT_MIN;
107  this->Extents[4] = VTK_INT_MAX;
108  this->Extents[5] = VTK_INT_MIN;
109  }
110 
117 
118  float CellStep[3];
119  double DatasetStepSize[3];
120 
125  double LoadedBounds[6];
126  double LoadedBoundsAA[6];
127  double VolumeGeometry[24];
128  int Extents[6];
129  };
130 
131  vtkTypeMacro(vtkVolumeTexture, vtkObject);
132  void PrintSelf(ostream& os, vtkIndent indent) override;
133 
137  void SetPartitions(int const i, int const j, int const k);
139 
146  bool LoadVolume(vtkRenderer* ren, vtkImageData* data, vtkDataArray* scalars, int const isCell,
147  int const interpolation);
148 
154 
160 
170 
175 
182  static void GetScaleAndBias(const int scalarType, float* scalarRange, float& scale, float& bias);
184 
186  float Scale[4];
187  float Bias[4];
188  float ScalarRange[4][2];
189  float CellSpacing[3];
192 
193  int IsCellData = 0;
195  float AdjustedTexMin[4];
196  float AdjustedTexMax[4];
197 
198 protected:
200  ~vtkVolumeTexture() override;
201 
202 private:
203  vtkVolumeTexture(const vtkVolumeTexture&) = delete;
204  void operator=(const vtkVolumeTexture&) = delete;
205 
210  bool LoadTexture(int const interpolation, VolumeBlock* volBlock);
211 
215  void SplitVolume(vtkImageData* imageData, Size3 const& part);
216 
217  void CreateBlocks(unsigned int const format, unsigned int const internalFormat, int const type);
218 
219  void AdjustExtentForCell(Size6& extent);
220  Size3 ComputeBlockSize(int* extent);
221 
226  void SelectTextureFormat(unsigned int& format, unsigned int& internalFormat, int& type,
227  int const scalarType, int const noOfComponents);
228 
232  void ClearBlocks();
233 
237  // can be combined into one call
238  void ComputeBounds(VolumeBlock* block);
239  void UpdateTextureToDataMatrix(VolumeBlock* block);
240 
259  void ComputeCellToPointMatrix(int extents[6]);
260 
262 
270  bool AreDimensionsValid(
271  vtkTextureObject* texture, int const width, int const height, int const depth);
272 
273  bool SafeLoadTexture(vtkTextureObject* texture, int const width, int const height,
274  int const depth, int numComps, int dataType, void* dataPtr);
276 
277  void UpdateInterpolationType(int const interpolation);
278  void SetInterpolation(int const interpolation);
279 
280  //----------------------------------------------------------------------------
281  vtkTimeStamp UpdateTime;
282 
284  std::vector<vtkImageData*> ImageDataBlocks;
285  std::map<vtkImageData*, VolumeBlock*> ImageDataBlockMap;
286  std::vector<VolumeBlock*> SortedVolumeBlocks;
287  size_t CurrentBlockIdx;
288  bool StreamBlocks;
289 
290  std::vector<Size3> TextureSizes;
291  Size6 FullExtent;
292  Size3 FullSize;
293  Size3 Partitions;
294 
295  vtkDataArray* Scalars;
296 };
297 
298 #endif // vtkVolumeTexture_h
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
topologically and geometrically regular array of data
Definition: vtkImageData.h:42
a simple class to control print indentation
Definition: vtkIndent.h:34
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:36
abstract base class for most VTK objects
Definition: vtkObject.h:54
abstract specification for renderers
Definition: vtkRenderer.h:59
abstracts an OpenGL texture object.
record modification and/or execution time
Definition: vtkTimeStamp.h:33
represents the common properties for rendering a volume.
Creates and manages the volume texture rendered by vtkOpenGLGPUVolumeRayCastMapper.
static vtkVolumeTexture * New()
VolumeBlock * GetNextBlock()
Return the next volume block to be rendered and load its data.
vtkTimeStamp UploadTime
bool LoadVolume(vtkRenderer *ren, vtkImageData *data, vtkDataArray *scalars, int const isCell, int const interpolation)
Loads the data array into the texture in the case only a single block is is defined.
vtkNew< vtkMatrix4x4 > CellToPointMatrix
vtkDataArray * GetLoadedScalars()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
const Size3 & GetPartitions()
void UpdateVolume(vtkVolumeProperty *property)
It currently only calls SetInterpolation internally.
void ReleaseGraphicsResources(vtkWindow *win)
Clean-up acquired graphics resources.
~vtkVolumeTexture() override
void SetPartitions(int const i, int const j, int const k)
Set a number of blocks per axis.
void SortBlocksBackToFront(vtkRenderer *ren, vtkMatrix4x4 *volumeMat)
If streaming the data array as separate blocks, sort them back to front.
VolumeBlock * GetCurrentBlock()
Return the currently loaded block.
static void GetScaleAndBias(const int scalarType, float *scalarRange, float &scale, float &bias)
Get the scale and bias values given a VTK scalar type and a finite range.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
@ scale
Definition: vtkX3D.h:235
@ extent
Definition: vtkX3D.h:351
@ type
Definition: vtkX3D.h:522
@ height
Definition: vtkX3D.h:260
@ data
Definition: vtkX3D.h:321
VolumeBlock(vtkImageData *imData, vtkTextureObject *tex, Size3 const &texSize)
vtkNew< vtkMatrix4x4 > TextureToDataset
vtkNew< vtkMatrix4x4 > TextureToDatasetInv
vtkTextureObject * TextureObject
int vtkIdType
Definition: vtkType.h:338
#define VTK_INT_MIN
Definition: vtkType.h:154
#define VTK_INT_MAX
Definition: vtkType.h:155