Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkVtkMapper.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkVtkMapper.h"
18 
20 {
21 }
22 
24 {
25 }
26 
28 {
29  VtkMapperLocalStorage *ls = m_VtkMapperLSH.GetLocalStorage(renderer);
30  if (ls->m_ShaderProgram)
31  {
32  ls->m_ShaderProgram->Activate();
33  }
34 
35  switch (type)
36  {
38  this->MitkRenderOpaqueGeometry(renderer);
39  break;
41  this->MitkRenderTranslucentGeometry(renderer);
42  break;
44  this->MitkRenderOverlay(renderer);
45  break;
47  this->MitkRenderVolumetricGeometry(renderer);
48  break;
49  }
50 
51  if (ls->m_ShaderProgram)
52  {
53  ls->m_ShaderProgram->Deactivate();
54  }
55 }
56 
58 {
59  return true;
60 }
61 
63 {
64  bool visible = true;
65  GetDataNode()->GetVisibility(visible, renderer, "visible");
66  if (!visible)
67  return;
68 
69  if (this->GetVtkProp(renderer)->GetVisibility())
70  {
71  GetVtkProp(renderer)->RenderOverlay(renderer->GetVtkRenderer());
72  }
73 }
74 
76 {
77  bool visible = true;
78 
79  GetDataNode()->GetVisibility(visible, renderer, "visible");
80  if (!visible)
81  return;
82 
83  if (this->GetVtkProp(renderer)->GetVisibility())
84  {
85  GetVtkProp(renderer)->RenderOpaqueGeometry(renderer->GetVtkRenderer());
86  }
87 }
88 
90 {
91  bool visible = true;
92  GetDataNode()->GetVisibility(visible, renderer, "visible");
93  if (!visible)
94  return;
95 
96  if (this->GetVtkProp(renderer)->GetVisibility())
97  {
98  GetVtkProp(renderer)->RenderTranslucentPolygonalGeometry(renderer->GetVtkRenderer());
99  }
100 }
101 
103 {
105  if (shaderRepo)
106  {
107  VtkMapperLocalStorage *ls = m_VtkMapperLSH.GetLocalStorage(renderer);
108  shaderRepo->UpdateShaderProgram(ls->m_ShaderProgram, this->GetDataNode(), renderer);
109  }
110 }
111 
113 {
114  bool visible = true;
115  GetDataNode()->GetVisibility(visible, renderer, "visible");
116  if (!visible)
117  return;
118 
119  if (GetVtkProp(renderer)->GetVisibility())
120  {
121  GetVtkProp(renderer)->RenderVolumetricGeometry(renderer->GetVtkRenderer());
122  }
123 }
124 
125 bool mitk::VtkMapper::HasVtkProp(const vtkProp *prop, BaseRenderer *renderer)
126 {
127  vtkProp *myProp = this->GetVtkProp(renderer);
128 
129  // TODO: check if myProp is a vtkAssembly and if so, check if prop is contained in its leafs
130  return (prop == myProp);
131 }
132 
134 {
135  if (mapper)
136  mapper->SetImmediateModeRendering(mitk::VtkPropRenderer::useImmediateModeRendering());
137 }
138 
140 {
141  vtkLinearTransform *vtktransform = GetDataNode()->GetVtkTransform(this->GetTimestep());
142 
143  vtkProp3D *prop = dynamic_cast<vtkProp3D *>(GetVtkProp(renderer));
144  if (prop)
145  prop->SetUserTransform(vtktransform);
146 }
147 
149 {
150  float rgba[4] = {1.0f, 1.0f, 1.0f, 1.0f};
151  DataNode *node = GetDataNode();
152 
153  // check for color prop and use it for rendering if it exists
154  node->GetColor(rgba, renderer, "color");
155  // check for opacity prop and use it for rendering if it exists
156  node->GetOpacity(rgba[3], renderer, "opacity");
157 
158  double drgba[4] = {rgba[0], rgba[1], rgba[2], rgba[3]};
159  actor->GetProperty()->SetColor(drgba);
160  actor->GetProperty()->SetOpacity(drgba[3]);
161 }
virtual void MitkRenderTranslucentGeometry(BaseRenderer *renderer)
Checks visiblity and renders transparent geometry.
virtual bool HasVtkProp(const vtkProp *prop, BaseRenderer *renderer)
Returns true if this mapper owns the specified vtkProp for the given BaseRenderer.
Organizes the rendering process.
static IShaderRepository * GetShaderRepository()
Get an IShaderRepository instance.
virtual void ApplyColorAndOpacityProperties(mitk::BaseRenderer *renderer, vtkActor *actor) override
Apply color and opacity properties read from the PropertyList. Called by mapper subclasses.
void MitkRender(mitk::BaseRenderer *renderer, mitk::VtkPropRenderer::RenderType type) override
Determines which geometry should be rendered (opaque, translucent, volumetric, overlay) and calls the...
virtual ~VtkMapper()
virtual bool IsVtkBased() const override
Returns whether this is an vtk-based mapper.
mitk::IShaderRepository::ShaderProgram::Pointer m_ShaderProgram
virtual void MitkRenderVolumetricGeometry(BaseRenderer *renderer)
Checks visibility and renders volumes.
Management class for vtkShader XML descriptions.
bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
virtual void MitkRenderOverlay(BaseRenderer *renderer)
Checks visibility and renders the overlay.
virtual void UpdateShaderProgram(mitk::IShaderRepository::ShaderProgram *shaderProgram, mitk::DataNode *node, mitk::BaseRenderer *renderer) const =0
Applies shader and shader specific variables of the specified DataNode to the VTK object by updating ...
virtual void UpdateVtkTransform(mitk::BaseRenderer *renderer)
Set the vtkTransform of the m_Prop3D for the current time step of renderer.
static void SetVtkMapperImmediateModeRendering(vtkMapper *mapper)
Re-issues all drawing commands required to describe the entire scene each time a new frame is require...
static bool useImmediateModeRendering()
virtual void MitkRenderOpaqueGeometry(BaseRenderer *renderer)
Checks visibility and renders untransparent geometry.
vtkRenderer * GetVtkRenderer() const
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
void ApplyShaderProperties(mitk::BaseRenderer *renderer)
SHADERTODO.