iMSTK
Interactive Medical Simulation Toolkit
imstkVTKVolumeRenderDelegate.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkVTKVolumeRenderDelegate.h"
8 #include "imstkVolumeRenderMaterial.h"
9 #include "imstkVisualModel.h"
10 
11 #include <vtkGPUVolumeRayCastMapper.h>
12 #include <vtkVolume.h>
13 #include <vtkVolumeProperty.h>
14 
15 namespace imstk
16 {
17 void
19 {
20  std::shared_ptr<VolumeRenderMaterial> material = std::dynamic_pointer_cast<VolumeRenderMaterial>(m_visualModel->getRenderMaterial());
21 
22  if (material != nullptr)
23  {
24  if (vtkSmartPointer<vtkVolumeMapper> volumeMapper = vtkVolumeMapper::SafeDownCast(m_mapper))
25  {
26  if (vtkSmartPointer<vtkGPUVolumeRayCastMapper> volumeRayCastMapper = vtkGPUVolumeRayCastMapper::SafeDownCast(volumeMapper))
27  {
28  volumeRayCastMapper->SetAutoAdjustSampleDistances(material->getUseAutoSample());
29  volumeRayCastMapper->SetSampleDistance(material->getSampleDistance());
30  }
31 
32  switch (material->getBlendMode())
33  {
34  case RenderMaterial::BlendMode::Alpha:
35  volumeMapper->SetBlendMode(vtkVolumeMapper::COMPOSITE_BLEND);
36  break;
37  case RenderMaterial::BlendMode::Additive:
38  volumeMapper->SetBlendMode(vtkVolumeMapper::ADDITIVE_BLEND);
39  break;
40  case RenderMaterial::BlendMode::MaximumIntensity:
41  volumeMapper->SetBlendMode(vtkVolumeMapper::MAXIMUM_INTENSITY_BLEND);
42  break;
43  case RenderMaterial::BlendMode::MinimumIntensity:
44  volumeMapper->SetBlendMode(vtkVolumeMapper::MINIMUM_INTENSITY_BLEND);
45  break;
46  default:
47  volumeMapper->SetBlendMode(vtkVolumeMapper::COMPOSITE_BLEND);
48  break;
49  }
50  }
51 
52  if (vtkSmartPointer<vtkVolume> volume = vtkVolume::SafeDownCast(m_actor))
53  {
54  volume->SetProperty(material->getVolumeProperty());
55  }
56  }
57 
58  m_actor->SetVisibility(m_visualModel->isVisible() ? 1 : 0);
59 }
60 } // namespace imstk
std::shared_ptr< VisualModel > m_visualModel
imstk visual model (contains data (geometry) and render specification (render material)) ...
Compound Geometry.
void updateRenderProperties() override
Updates the actor and mapper properties from the currently set VisualModel.