VTK  9.0.1
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 =========================================================================*/
33 #ifndef vtkGPUVolumeRayCastMapper_h
34 #define vtkGPUVolumeRayCastMapper_h
35 #include <unordered_map> // For std::unordered_map
36 #include <vector> // For std::vector
37 
38 #include "vtkVolumeMapper.h"
39 #include <vtkRenderingVolumeModule.h> // For export macro
40 
41 class vtkContourValues;
42 class vtkRenderWindow;
43 class vtkVolumeProperty;
44 
45 class VTKRENDERINGVOLUME_EXPORT vtkGPUVolumeRayCastMapper : public vtkVolumeMapper
46 {
47 public:
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
53 
59  vtkSetClampMacro(AutoAdjustSampleDistances, vtkTypeBool, 0, 1);
60  vtkGetMacro(AutoAdjustSampleDistances, vtkTypeBool);
61  vtkBooleanMacro(AutoAdjustSampleDistances, vtkTypeBool);
63 
65 
70  vtkSetClampMacro(LockSampleDistanceToInputSpacing, vtkTypeBool, 0, 1);
71  vtkGetMacro(LockSampleDistanceToInputSpacing, vtkTypeBool);
72  vtkBooleanMacro(LockSampleDistanceToInputSpacing, vtkTypeBool);
74 
76 
81  vtkSetClampMacro(UseJittering, vtkTypeBool, 0, 1);
82  vtkGetMacro(UseJittering, vtkTypeBool);
83  vtkBooleanMacro(UseJittering, vtkTypeBool);
85 
87 
95  vtkSetClampMacro(UseDepthPass, vtkTypeBool, 0, 1);
96  vtkGetMacro(UseDepthPass, vtkTypeBool);
97  vtkBooleanMacro(UseDepthPass, vtkTypeBool);
99 
105  vtkContourValues* GetDepthPassContourValues();
106 
108 
114  vtkSetMacro(SampleDistance, float);
115  vtkGetMacro(SampleDistance, float);
117 
119 
126  vtkSetClampMacro(ImageSampleDistance, float, 0.1f, 100.0f);
127  vtkGetMacro(ImageSampleDistance, float);
129 
131 
135  vtkSetClampMacro(MinimumImageSampleDistance, float, 0.1f, 100.0f);
136  vtkGetMacro(MinimumImageSampleDistance, float);
138 
140 
144  vtkSetClampMacro(MaximumImageSampleDistance, float, 0.1f, 100.0f);
145  vtkGetMacro(MaximumImageSampleDistance, float);
147 
149 
162  vtkSetMacro(FinalColorWindow, float);
163  vtkGetMacro(FinalColorWindow, float);
164  vtkSetMacro(FinalColorLevel, float);
165  vtkGetMacro(FinalColorLevel, float);
167 
169 
174  vtkSetMacro(MaxMemoryInBytes, vtkIdType);
175  vtkGetMacro(MaxMemoryInBytes, vtkIdType);
177 
179 
184  vtkSetClampMacro(MaxMemoryFraction, float, 0.1f, 1.0f);
185  vtkGetMacro(MaxMemoryFraction, float);
187 
189 
197  vtkSetMacro(ReportProgress, bool);
198  vtkGetMacro(ReportProgress, bool);
200 
207  virtual int IsRenderSupported(
208  vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property))
209  {
210  return 0;
211  }
212 
213  void CreateCanonicalView(vtkRenderer* ren, vtkVolume* volume, vtkImageData* image, int blend_mode,
214  double viewDirection[3], double viewUp[3]);
215 
217 
237  void SetMaskInput(vtkImageData* mask);
238  vtkGetObjectMacro(MaskInput, vtkImageData);
240 
241  enum
242  {
243  BinaryMaskType = 0,
244  LabelMapMaskType
245  };
246 
248 
252  vtkSetMacro(MaskType, int);
253  vtkGetMacro(MaskType, int);
254  void SetMaskTypeToBinary();
255  void SetMaskTypeToLabelMap();
257 
259 
267  vtkSetClampMacro(MaskBlendFactor, float, 0.0f, 1.0f);
268  vtkGetMacro(MaskBlendFactor, float);
270 
272 
286  vtkSetMacro(RenderToImage, vtkTypeBool);
287  vtkGetMacro(RenderToImage, vtkTypeBool);
288  vtkBooleanMacro(RenderToImage, vtkTypeBool);
290 
292 
297  vtkSetMacro(DepthImageScalarType, int);
298  vtkGetMacro(DepthImageScalarType, int);
299  void SetDepthImageScalarTypeToUnsignedChar();
300  void SetDepthImageScalarTypeToUnsignedShort();
301  void SetDepthImageScalarTypeToFloat();
303 
305 
316  vtkSetMacro(ClampDepthToBackface, vtkTypeBool);
317  vtkGetMacro(ClampDepthToBackface, vtkTypeBool);
318  vtkBooleanMacro(ClampDepthToBackface, vtkTypeBool);
320 
327  virtual void GetDepthImage(vtkImageData*) {}
328 
335  virtual void GetColorImage(vtkImageData*) {}
336 
341  void Render(vtkRenderer*, vtkVolume*) override;
342 
347  virtual void GPURender(vtkRenderer*, vtkVolume*) {}
348 
356 
369  virtual void GetReductionRatio(double ratio[3]) = 0;
370 
372  {
373  SCALAR = 0, // default
374  NATIVE
375  };
376 
378 
394  vtkSetMacro(ColorRangeType, int);
395  vtkGetMacro(ColorRangeType, int);
396  vtkSetMacro(ScalarOpacityRangeType, int);
397  vtkGetMacro(ScalarOpacityRangeType, int);
398  vtkSetMacro(GradientOpacityRangeType, int);
399  vtkGetMacro(GradientOpacityRangeType, int);
401 
402  vtkImageData* GetInput() override { return this->GetInput(0); };
403 
405 
409  void RemoveInputConnection(int port, vtkAlgorithmOutput* input) override;
410  void RemoveInputConnection(int port, int idx) override;
411  void SetInputConnection(int port, vtkAlgorithmOutput* input) override;
413  {
414  this->SetInputConnection(0, input);
415  }
417 
421  int GetInputCount();
422 
423  vtkImageData* GetTransformedInput(const int port = 0);
424 
425  double* GetBoundsFromPort(const int port) VTK_SIZEHINT(6);
426 
427 protected:
429  ~vtkGPUVolumeRayCastMapper() override;
430 
439  int FillInputPortInformation(int port, vtkInformation* info) override;
440 
452  void TransformInput(const int port);
453 
455 
464  int ValidateRender(vtkRenderer*, vtkVolume*);
465  int ValidateInputs();
466  int ValidateInput(vtkVolumeProperty* property, const int port);
468 
470 
474  void CloneInputs();
475  void CloneInput(vtkImageData* input, const int port);
477 
478  // Special version of render called during the creation
479  // of a canonical view.
480  void CanonicalViewRender(vtkRenderer*, vtkVolume*);
481 
482  // Methods called by the AMR Volume Mapper.
483  virtual void PreRender(vtkRenderer* ren, vtkVolume* vol, double datasetBounds[6],
484  double scalarRange[2], int numberOfScalarComponents, unsigned int numberOfLevels) = 0;
485 
486  // \pre input is up-to-date
487  virtual void RenderBlock(vtkRenderer* ren, vtkVolume* vol, unsigned int level) = 0;
488 
489  virtual void PostRender(vtkRenderer* ren, int numberOfScalarComponents) = 0;
490  vtkImageData* GetInput(const int port) override;
491 
497  void SetCellFlag(int cellFlag);
498  void RemovePortInternal(const int port);
499 
505 
506  // Render to texture mode flag
508 
509  // Depth image scalar type
511 
512  // Clamp depth values to the depth of the face at which the ray
513  // exits the volume
515 
516  // Enable / disable stochastic jittering
518 
519  // Enable / disable two pass rendering
522 
523  // The distance between sample points along the ray
525 
529 
532 
533  // 1 if we are generating the canonical image, 0 otherwise
536 
538 
542  vtkSetClampMacro(AMRMode, vtkTypeBool, 0, 1);
543  vtkGetMacro(AMRMode, vtkTypeBool);
544  vtkBooleanMacro(AMRMode, vtkTypeBool);
546 
549  int MaskType;
550 
552 
553  // Transfer function range type
557 
558  // Point data or cell data (or field data, not handled) ?
559  int CellFlag;
560 
573  virtual void ClipCroppingRegionPlanes();
574 
575  using DataMap = std::unordered_map<int, vtkImageData*>;
576  void SetTransformedInput(vtkImageData*);
577  vtkImageData* FindData(int port, DataMap& container);
578 
579  double ClippedCroppingRegionPlanes[6];
580 
583 
585  std::vector<int> Ports;
586  std::vector<int> RemovedPorts;
588 
594 
595 private:
597  void operator=(const vtkGPUVolumeRayCastMapper&) = delete;
598 };
599 
600 #endif
virtual void GPURender(vtkRenderer *, vtkVolume *)
Handled in the subclass - the actual render method.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
helper object to manage setting and generating contour values
vtkImageData * GetInput() override
Set/Get the input data.
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:44
std::unordered_map< int, vtkImageData * > DataMap
Abstract class for a volume mapper.
Store vtkAlgorithm input/output information.
virtual void GetDepthImage(vtkImageData *)
Low level API to export the depth texture as vtkImageData in RenderToImage mode.
virtual void GetColorImage(vtkImageData *)
Low level API to export the color texture as vtkImageData in RenderToImage mode.
abstract specification for renderers
Definition: vtkRenderer.h:61
int vtkIdType
Definition: vtkType.h:338
void Render(vtkRenderer *ren, vtkVolume *vol) override=0
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
Proxy object to connect input/output ports.
int vtkTypeBool
Definition: vtkABI.h:69
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
a simple class to control print indentation
Definition: vtkIndent.h:33
int FillInputPortInformation(int, vtkInformation *) override
Fill the input port information objects for this algorithm.
topologically and geometrically regular array of data
Definition: vtkImageData.h:41
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
virtual vtkImageData * GetInput()
Set/Get the input data.
#define VTK_SIZEHINT(...)
represents the common properties for rendering a volume.
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...
create a window for renderers to draw into
DataMap LastInputs
This is needed only to check if the input data has been changed since the last Render() call...
static vtkAlgorithm * New()
Ray casting performed on the GPU.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetInputConnection(vtkAlgorithmOutput *input) override
Add/Remove input connections.
virtual void RemoveInputConnection(int port, vtkAlgorithmOutput *input)
Remove a connection from the given input port index.