VTK  9.7.1
vtkVolumeTexture.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
56 #ifndef vtkVolumeTexture_h
57 #define vtkVolumeTexture_h
58 #include <map> // For ImageDataBlockMap
59 #include <vector> // For ImageDataBlocks
60 
61 #include "vtkMatrix4x4.h" // For vtkMatrix4
62 #include "vtkNew.h" // For vtkNew
63 #include "vtkObject.h"
64 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
65 #include "vtkSmartPointer.h" // For SmartPointer
66 #include "vtkTimeStamp.h" // For UploadTime
67 #include "vtkTuple.h" // For Size6 and Size3
68 
69 VTK_ABI_NAMESPACE_BEGIN
70 class vtkDataArray;
71 class vtkDataSet;
72 class vtkImageData;
73 class vtkRenderer;
74 class vtkTextureObject;
75 class vtkVolumeProperty;
76 class vtkWindow;
77 
78 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkVolumeTexture : public vtkObject
79 {
80  typedef vtkTuple<int, 6> Size6;
81  typedef vtkTuple<int, 3> Size3;
82 
83 public:
84  static vtkVolumeTexture* New();
85 
86  struct VolumeBlock
87  {
88  VolumeBlock(vtkDataSet* dataset, vtkTextureObject* tex, Size3 const& texSize)
89  {
90  // Block extent is stored in vtkDataSet
91  DataSet = dataset;
92  TextureObject = tex;
93  TextureSize = texSize;
94  TupleIndex = 0;
95 
96  this->Extents[0] = VTK_INT_MAX;
97  this->Extents[1] = VTK_INT_MIN;
98  this->Extents[2] = VTK_INT_MAX;
99  this->Extents[3] = VTK_INT_MIN;
100  this->Extents[4] = VTK_INT_MAX;
101  this->Extents[5] = VTK_INT_MIN;
102  }
103 
106  Size3 TextureSize;
110 
111  float CellStep[3];
112  double DatasetStepSize[3];
113 
118  double LoadedBounds[6];
119  double LoadedBoundsAA[6];
120  double VolumeGeometry[24];
121  int Extents[6];
122  };
123 
124  vtkTypeMacro(vtkVolumeTexture, vtkObject);
125  void PrintSelf(ostream& os, vtkIndent indent) override;
126 
130  void SetPartitions(int x, int y, int z);
131  const Size3& GetPartitions();
132 
139  bool LoadVolume(
140  vtkRenderer* ren, vtkDataSet* data, vtkDataArray* scalars, int isCell, int interpolation);
141 
146  void UpdateVolume(vtkVolumeProperty* property);
147 
152  void SortBlocksBackToFront(vtkRenderer* ren, vtkMatrix4x4* volumeMat);
153 
158  VolumeBlock* GetNextBlock();
162  VolumeBlock* GetCurrentBlock();
163 
167  void ReleaseGraphicsResources(vtkWindow* win);
168 
175  static void GetScaleAndBias(int scalarType, float* scalarRange, float& scale, float& bias);
176  vtkDataArray* GetLoadedScalars();
177 
179  float Scale[4];
180  float Bias[4];
181  float ScalarRange[4][2];
182  float CellSpacing[3];
185 
186  int IsCellData = 0;
188  float AdjustedTexMin[4];
189  float AdjustedTexMax[4];
190 
192 
193  int CoordsTexSizes[3];
194  float CoordsScale[3];
195  float CoordsBias[3];
196 
198 
199 protected:
201  ~vtkVolumeTexture() override;
202 
203 private:
204  vtkVolumeTexture(const vtkVolumeTexture&) = delete;
205  void operator=(const vtkVolumeTexture&) = delete;
206 
211  bool LoadTexture(int interpolation, VolumeBlock* volBlock);
212 
216  void SplitVolume(vtkImageData* imageData, Size3 const& part);
217 
218  void CreateBlocks(unsigned int format, unsigned int internalFormat, int type);
219 
220  void AdjustExtentForCell(Size6& extent);
221  Size3 ComputeBlockSize(VTK_FUTURE_CONST int extent[6]);
222 
227  void SelectTextureFormat(unsigned int& format, unsigned int& internalFormat, int& type,
228  int scalarType, int noOfComponents);
229 
233  void ClearBlocks();
234 
238  // can be combined into one call
239  void ComputeBounds(VolumeBlock* block);
240  void UpdateTextureToDataMatrix(VolumeBlock* block);
241 
260  void ComputeCellToPointMatrix(int extents[6]);
261 
263 
271  bool AreDimensionsValid(vtkTextureObject* texture, int width, int height, int depth);
272 
273  bool SafeLoadTexture(vtkTextureObject* texture, int width, int height, int depth, int numComps,
274  int dataType, void* dataPtr);
276 
277  void UpdateInterpolationType(int interpolation);
278  void SetInterpolation(int interpolation);
279 
280  //----------------------------------------------------------------------------
281  vtkTimeStamp UpdateTime;
282 
284  std::vector<vtkDataSet*> ImageDataBlocks;
285  std::map<vtkDataSet*, 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 VTK_ABI_NAMESPACE_END
299 #endif // vtkVolumeTexture_h
VolumeBlock(vtkDataSet *dataset, vtkTextureObject *tex, Size3 const &texSize)
abstract base class for most VTK objects
Definition: vtkObject.h:52
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:31
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.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
#define VTK_INT_MAX
Definition: vtkType.h:192
record modification and/or execution time
Definition: vtkTimeStamp.h:24
abstract specification for renderers
Definition: vtkRenderer.h:63
int vtkIdType
Definition: vtkType.h:363
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
vtkTextureObject * TextureObject
vtkSmartPointer< vtkTextureObject > BlankingTex
a simple class to control print indentation
Definition: vtkIndent.h:28
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
std::map< std::string, DataArray > DataSet
key: variable name, value: DataArray
Definition: VTXTypes.h:28
represents the common properties for rendering a volume.
vtkNew< vtkMatrix4x4 > TextureToDataset
vtkSmartPointer< vtkTextureObject > CoordsTex
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:191