VTK  9.0.3
vtkGPUVolumeRayCastMapper.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkGPUVolumeRayCastMapper.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 =========================================================================*/
39 #ifndef vtkGPUVolumeRayCastMapper_h
40 #define vtkGPUVolumeRayCastMapper_h
41 #include <unordered_map> // For std::unordered_map
42 #include <vector> // For std::vector
43 
44 #include "vtkVolumeMapper.h"
45 #include <vtkRenderingVolumeModule.h> // For export macro
46 
47 class vtkContourValues;
48 class vtkRenderWindow;
49 class vtkVolumeProperty;
50 
51 class VTKRENDERINGVOLUME_EXPORT vtkGPUVolumeRayCastMapper : public vtkVolumeMapper
52 {
53 public:
56  void PrintSelf(ostream& os, vtkIndent indent) override;
57 
59 
65  vtkSetClampMacro(AutoAdjustSampleDistances, vtkTypeBool, 0, 1);
66  vtkGetMacro(AutoAdjustSampleDistances, vtkTypeBool);
67  vtkBooleanMacro(AutoAdjustSampleDistances, vtkTypeBool);
69 
71 
76  vtkSetClampMacro(LockSampleDistanceToInputSpacing, vtkTypeBool, 0, 1);
77  vtkGetMacro(LockSampleDistanceToInputSpacing, vtkTypeBool);
78  vtkBooleanMacro(LockSampleDistanceToInputSpacing, vtkTypeBool);
80 
82 
87  vtkSetClampMacro(UseJittering, vtkTypeBool, 0, 1);
88  vtkGetMacro(UseJittering, vtkTypeBool);
89  vtkBooleanMacro(UseJittering, vtkTypeBool);
91 
93 
101  vtkSetClampMacro(UseDepthPass, vtkTypeBool, 0, 1);
102  vtkGetMacro(UseDepthPass, vtkTypeBool);
103  vtkBooleanMacro(UseDepthPass, vtkTypeBool);
105 
112 
114 
120  vtkSetMacro(SampleDistance, float);
121  vtkGetMacro(SampleDistance, float);
123 
125 
132  vtkSetClampMacro(ImageSampleDistance, float, 0.1f, 100.0f);
133  vtkGetMacro(ImageSampleDistance, float);
135 
137 
141  vtkSetClampMacro(MinimumImageSampleDistance, float, 0.1f, 100.0f);
142  vtkGetMacro(MinimumImageSampleDistance, float);
144 
146 
150  vtkSetClampMacro(MaximumImageSampleDistance, float, 0.1f, 100.0f);
151  vtkGetMacro(MaximumImageSampleDistance, float);
153 
155 
168  vtkSetMacro(FinalColorWindow, float);
169  vtkGetMacro(FinalColorWindow, float);
170  vtkSetMacro(FinalColorLevel, float);
171  vtkGetMacro(FinalColorLevel, float);
173 
175 
180  vtkSetMacro(MaxMemoryInBytes, vtkIdType);
181  vtkGetMacro(MaxMemoryInBytes, vtkIdType);
183 
185 
190  vtkSetClampMacro(MaxMemoryFraction, float, 0.1f, 1.0f);
191  vtkGetMacro(MaxMemoryFraction, float);
193 
195 
203  vtkSetMacro(ReportProgress, bool);
204  vtkGetMacro(ReportProgress, bool);
206 
213  virtual int IsRenderSupported(
214  vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property))
215  {
216  return 0;
217  }
218 
219  void CreateCanonicalView(vtkRenderer* ren, vtkVolume* volume, vtkImageData* image, int blend_mode,
220  double viewDirection[3], double viewUp[3]);
221 
223 
244  vtkGetObjectMacro(MaskInput, vtkImageData);
246 
247  enum
248  {
249  BinaryMaskType = 0,
250  LabelMapMaskType
251  };
252 
254 
258  vtkSetMacro(MaskType, int);
259  vtkGetMacro(MaskType, int);
263 
265 
273  vtkSetClampMacro(MaskBlendFactor, float, 0.0f, 1.0f);
274  vtkGetMacro(MaskBlendFactor, float);
276 
278 
292  vtkSetMacro(RenderToImage, vtkTypeBool);
293  vtkGetMacro(RenderToImage, vtkTypeBool);
294  vtkBooleanMacro(RenderToImage, vtkTypeBool);
296 
298 
303  vtkSetMacro(DepthImageScalarType, int);
304  vtkGetMacro(DepthImageScalarType, int);
309 
311 
322  vtkSetMacro(ClampDepthToBackface, vtkTypeBool);
323  vtkGetMacro(ClampDepthToBackface, vtkTypeBool);
324  vtkBooleanMacro(ClampDepthToBackface, vtkTypeBool);
326 
333  virtual void GetDepthImage(vtkImageData*) {}
334 
341  virtual void GetColorImage(vtkImageData*) {}
342 
347  void Render(vtkRenderer*, vtkVolume*) override;
348 
353  virtual void GPURender(vtkRenderer*, vtkVolume*) {}
354 
362 
375  virtual void GetReductionRatio(double ratio[3]) = 0;
376 
378  {
379  SCALAR = 0, // default
380  NATIVE
381  };
382 
384 
400  vtkSetMacro(ColorRangeType, int);
401  vtkGetMacro(ColorRangeType, int);
402  vtkSetMacro(ScalarOpacityRangeType, int);
403  vtkGetMacro(ScalarOpacityRangeType, int);
404  vtkSetMacro(GradientOpacityRangeType, int);
405  vtkGetMacro(GradientOpacityRangeType, int);
407 
408  vtkImageData* GetInput() override { return this->GetInput(0); };
409 
411 
415  void RemoveInputConnection(int port, vtkAlgorithmOutput* input) override;
416  void RemoveInputConnection(int port, int idx) override;
417  void SetInputConnection(int port, vtkAlgorithmOutput* input) override;
419  {
420  this->SetInputConnection(0, input);
421  }
423 
428 
430 
431  double* GetBoundsFromPort(const int port) VTK_SIZEHINT(6);
432 
433 protected:
436 
446 
458  void TransformInput(const int port);
459 
461 
472  int ValidateInput(vtkVolumeProperty* property, const int port);
474 
476 
480  void CloneInputs();
481  void CloneInput(vtkImageData* input, const int port);
483 
484  // Special version of render called during the creation
485  // of a canonical view.
487 
488  // Methods called by the AMR Volume Mapper.
489  virtual void PreRender(vtkRenderer* ren, vtkVolume* vol, double datasetBounds[6],
490  double scalarRange[2], int numberOfScalarComponents, unsigned int numberOfLevels) = 0;
491 
492  // \pre input is up-to-date
493  virtual void RenderBlock(vtkRenderer* ren, vtkVolume* vol, unsigned int level) = 0;
494 
495  virtual void PostRender(vtkRenderer* ren, int numberOfScalarComponents) = 0;
496  vtkImageData* GetInput(const int port) override;
497 
503  void SetCellFlag(int cellFlag);
504  void RemovePortInternal(const int port);
505 
511 
512  // Render to texture mode flag
514 
515  // Depth image scalar type
517 
518  // Clamp depth values to the depth of the face at which the ray
519  // exits the volume
521 
522  // Enable / disable stochastic jittering
524 
525  // Enable / disable two pass rendering
528 
529  // The distance between sample points along the ray
531 
535 
538 
539  // 1 if we are generating the canonical image, 0 otherwise
542 
544 
548  vtkSetClampMacro(AMRMode, vtkTypeBool, 0, 1);
549  vtkGetMacro(AMRMode, vtkTypeBool);
550  vtkBooleanMacro(AMRMode, vtkTypeBool);
552 
555  int MaskType;
556 
558 
559  // Transfer function range type
563 
564  // Point data or cell data (or field data, not handled) ?
565  int CellFlag;
566 
579  virtual void ClipCroppingRegionPlanes();
580 
581  using DataMap = std::unordered_map<int, vtkImageData*>;
583  vtkImageData* FindData(int port, DataMap& container);
584 
585  double ClippedCroppingRegionPlanes[6];
586 
589 
591  std::vector<int> Ports;
592  std::vector<int> RemovedPorts;
594 
600 
601 private:
603  void operator=(const vtkGPUVolumeRayCastMapper&) = delete;
604 };
605 
606 #endif
Proxy object to connect input/output ports.
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
helper object to manage setting and generating contour values
Ray casting performed on the GPU.
virtual void GetDepthImage(vtkImageData *)
Low level API to export the depth texture as vtkImageData in RenderToImage mode.
vtkImageData * FindData(int port, DataMap &container)
virtual int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window), vtkVolumeProperty *vtkNotUsed(property))
Based on hardware and properties, we may or may not be able to render using 3D texture mapping.
void CloneInputs()
Shallow-copy the inputs into a transform-adjusted clone.
void RemoveInputConnection(int port, int idx) override
Remove a connection given by index idx.
virtual void GPURender(vtkRenderer *, vtkVolume *)
Handled in the subclass - the actual render method.
int ValidateRender(vtkRenderer *, vtkVolume *)
This method is used by the Render() method to validate everything before attempting to render.
vtkImageData * GetInput() override
virtual void GetColorImage(vtkImageData *)
Low level API to export the color texture as vtkImageData in RenderToImage mode.
double * GetBoundsFromPort(const int port)
void SetInputConnection(vtkAlgorithmOutput *input) override
void SetDepthImageScalarTypeToUnsignedShort()
void SetMaskInput(vtkImageData *mask)
Optionally, set a mask input.
~vtkGPUVolumeRayCastMapper() override
virtual void GetReductionRatio(double ratio[3])=0
Return how much the dataset has to be reduced in each dimension to fit on the GPU.
vtkImageData * GetInput(const int port) override
void RemovePortInternal(const int port)
DataMap LastInputs
This is needed only to check if the input data has been changed since the last Render() call.
void CreateCanonicalView(vtkRenderer *ren, vtkVolume *volume, vtkImageData *image, int blend_mode, double viewDirection[3], double viewUp[3])
void SetDepthImageScalarTypeToUnsignedChar()
void CloneInput(vtkImageData *input, const int port)
vtkContourValues * GetDepthPassContourValues()
Return handle to contour values container so that values can be set by the application.
int ValidateInput(vtkVolumeProperty *property, const int port)
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
void Render(vtkRenderer *, vtkVolume *) override
Initialize rendering for this volume.
void TransformInput(const int port)
A transformation is applied (translation) to the input.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetTransformedInput(vtkImageData *)
void RemoveInputConnection(int port, vtkAlgorithmOutput *input) override
Add/Remove input connections.
virtual void PreRender(vtkRenderer *ren, vtkVolume *vol, double datasetBounds[6], double scalarRange[2], int numberOfScalarComponents, unsigned int numberOfLevels)=0
std::unordered_map< int, vtkImageData * > DataMap
static vtkGPUVolumeRayCastMapper * New()
virtual void RenderBlock(vtkRenderer *ren, vtkVolume *vol, unsigned int level)=0
void SetInputConnection(int port, vtkAlgorithmOutput *input) override
Set the connection for the given input port index.
int GetInputCount()
Number of currently active ports.
virtual void ClipCroppingRegionPlanes()
Compute the cropping planes clipped by the bounds of the volume.
int FillInputPortInformation(int port, vtkInformation *info) override
Handle inputs.
vtkImageData * GetTransformedInput(const int port=0)
virtual void PostRender(vtkRenderer *ren, int numberOfScalarComponents)=0
void SetCellFlag(int cellFlag)
Called by the AMR Volume Mapper.
void CanonicalViewRender(vtkRenderer *, vtkVolume *)
topologically and geometrically regular array of data
Definition: vtkImageData.h:42
a simple class to control print indentation
Definition: vtkIndent.h:34
Store vtkAlgorithm input/output information.
create a window for renderers to draw into
abstract specification for renderers
Definition: vtkRenderer.h:68
Abstract class for a volume mapper.
represents the common properties for rendering a volume.
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:45
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
@ info
Definition: vtkX3D.h:382
@ level
Definition: vtkX3D.h:401
@ port
Definition: vtkX3D.h:453
@ image
Definition: vtkX3D.h:380
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:338
#define VTK_SIZEHINT(...)