VTK  9.3.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 
53 #ifndef vtkVolumeTexture_h
54 #define vtkVolumeTexture_h
55 #include <map> // For ImageDataBlockMap
56 #include <vector> // For ImageDataBlocks
57 
58 #include "vtkMatrix4x4.h" // For vtkMatrix4
59 #include "vtkNew.h" // For vtkNew
60 #include "vtkObject.h"
61 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
62 #include "vtkSmartPointer.h" // For SmartPointer
63 #include "vtkTimeStamp.h" // For UploadTime
64 #include "vtkTuple.h" // For Size6 and Size3
65 
66 VTK_ABI_NAMESPACE_BEGIN
67 class vtkDataArray;
68 class vtkDataSet;
69 class vtkImageData;
70 class vtkRenderer;
71 class vtkTextureObject;
72 class vtkVolumeProperty;
73 class vtkWindow;
74 
75 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkVolumeTexture : public vtkObject
76 {
77  typedef vtkTuple<int, 6> Size6;
78  typedef vtkTuple<int, 3> Size3;
79 
80 public:
81  static vtkVolumeTexture* New();
82 
83  struct VolumeBlock
84  {
85  VolumeBlock(vtkDataSet* dataset, vtkTextureObject* tex, Size3 const& texSize)
86  {
87  // Block extent is stored in vtkDataSet
88  DataSet = dataset;
89  TextureObject = tex;
90  TextureSize = texSize;
91  TupleIndex = 0;
92 
93  this->Extents[0] = VTK_INT_MAX;
94  this->Extents[1] = VTK_INT_MIN;
95  this->Extents[2] = VTK_INT_MAX;
96  this->Extents[3] = VTK_INT_MIN;
97  this->Extents[4] = VTK_INT_MAX;
98  this->Extents[5] = VTK_INT_MIN;
99  }
100 
103  Size3 TextureSize;
107 
108  float CellStep[3];
109  double DatasetStepSize[3];
110 
115  double LoadedBounds[6];
116  double LoadedBoundsAA[6];
117  double VolumeGeometry[24];
118  int Extents[6];
119  };
120 
121  vtkTypeMacro(vtkVolumeTexture, vtkObject);
122  void PrintSelf(ostream& os, vtkIndent indent) override;
123 
127  void SetPartitions(int x, int y, int z);
128  const Size3& GetPartitions();
129 
136  bool LoadVolume(
137  vtkRenderer* ren, vtkDataSet* data, vtkDataArray* scalars, int isCell, int interpolation);
138 
143  void UpdateVolume(vtkVolumeProperty* property);
144 
149  void SortBlocksBackToFront(vtkRenderer* ren, vtkMatrix4x4* volumeMat);
150 
155  VolumeBlock* GetNextBlock();
159  VolumeBlock* GetCurrentBlock();
160 
164  void ReleaseGraphicsResources(vtkWindow* win);
165 
172  static void GetScaleAndBias(int scalarType, float* scalarRange, float& scale, float& bias);
173  vtkDataArray* GetLoadedScalars();
174 
176  float Scale[4];
177  float Bias[4];
178  float ScalarRange[4][2];
179  float CellSpacing[3];
182 
183  int IsCellData = 0;
185  float AdjustedTexMin[4];
186  float AdjustedTexMax[4];
187 
189 
190  int CoordsTexSizes[3];
191  float CoordsScale[3];
192  float CoordsBias[3];
193 
195 
196 protected:
198  ~vtkVolumeTexture() override;
199 
200 private:
201  vtkVolumeTexture(const vtkVolumeTexture&) = delete;
202  void operator=(const vtkVolumeTexture&) = delete;
203 
208  bool LoadTexture(int interpolation, VolumeBlock* volBlock);
209 
213  void SplitVolume(vtkImageData* imageData, Size3 const& part);
214 
215  void CreateBlocks(unsigned int format, unsigned int internalFormat, int type);
216 
217  void AdjustExtentForCell(Size6& extent);
218  Size3 ComputeBlockSize(int* extent);
219 
224  void SelectTextureFormat(unsigned int& format, unsigned int& internalFormat, int& type,
225  int scalarType, int noOfComponents);
226 
230  void ClearBlocks();
231 
235  // can be combined into one call
236  void ComputeBounds(VolumeBlock* block);
237  void UpdateTextureToDataMatrix(VolumeBlock* block);
238 
257  void ComputeCellToPointMatrix(int extents[6]);
258 
260 
268  bool AreDimensionsValid(vtkTextureObject* texture, int width, int height, int depth);
269 
270  bool SafeLoadTexture(vtkTextureObject* texture, int width, int height, int depth, int numComps,
271  int dataType, void* dataPtr);
273 
274  void UpdateInterpolationType(int interpolation);
275  void SetInterpolation(int interpolation);
276 
277  //----------------------------------------------------------------------------
278  vtkTimeStamp UpdateTime;
279 
281  std::vector<vtkDataSet*> ImageDataBlocks;
282  std::map<vtkDataSet*, VolumeBlock*> ImageDataBlockMap;
283  std::vector<VolumeBlock*> SortedVolumeBlocks;
284  size_t CurrentBlockIdx;
285  bool StreamBlocks;
286 
287  std::vector<Size3> TextureSizes;
288  Size6 FullExtent;
289  Size3 FullSize;
290  Size3 Partitions;
291 
292  vtkDataArray* Scalars;
293 };
294 
295 VTK_ABI_NAMESPACE_END
296 #endif // vtkVolumeTexture_h
VolumeBlock(vtkDataSet *dataset, vtkTextureObject *tex, Size3 const &texSize)
abstract base class for most VTK objects
Definition: vtkObject.h:51
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
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:52
#define VTK_INT_MAX
Definition: vtkType.h:144
record modification and/or execution time
Definition: vtkTimeStamp.h:24
abstract specification for renderers
Definition: vtkRenderer.h:61
int vtkIdType
Definition: vtkType.h:315
window superclass for vtkRenderWindow
Definition: vtkWindow.h:27
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:42
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:143