Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkVtkWidgetRendering.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 "mitkVtkWidgetRendering.h"
18 
19 #include "mitkVtkLayerController.h"
20 
21 #include <itkMacro.h>
22 #include <itkObject.h>
23 #include <itksys/SystemTools.hxx>
24 #include <mitkConfig.h>
25 
26 #include <vtkObjectFactory.h>
27 #include <vtkRenderWindow.h>
28 #include <vtkRenderer.h>
29 #include <vtkRendererCollection.h>
30 
31 #include <vtkInteractorObserver.h>
32 
33 #include <algorithm>
34 
35 mitk::VtkWidgetRendering::VtkWidgetRendering() : m_RenderWindow(nullptr), m_VtkWidget(nullptr), m_IsEnabled(false)
36 {
38 }
39 
41 {
42  if (m_RenderWindow != nullptr)
43  if (this->IsEnabled())
44  this->Disable();
45 
46  if (m_Renderer != nullptr)
47  m_Renderer->Delete();
48 }
49 
55 void mitk::VtkWidgetRendering::SetRenderWindow(vtkRenderWindow *renderWindow)
56 {
57  m_RenderWindow = renderWindow;
58 }
59 
65 {
66  return m_RenderWindow;
67 }
68 
75 {
76  return m_Renderer;
77 }
78 
84 {
85  if (m_IsEnabled)
86  return;
87 
88  if (m_RenderWindow != nullptr)
89  {
90  vtkRenderWindowInteractor *interactor = m_RenderWindow->GetInteractor();
91 
92  if (m_VtkWidget != nullptr)
93  {
94  m_VtkWidget->SetInteractor(interactor);
95 
96  mitk::VtkLayerController *layerController = mitk::VtkLayerController::GetInstance(m_RenderWindow);
97 
98  if (layerController)
99  {
100  layerController->InsertForegroundRenderer(m_Renderer, false);
101  }
102 
103  m_IsEnabled = true;
104  }
105  }
106 }
107 
113 {
114  if (this->IsEnabled())
115  {
116  mitk::VtkLayerController *layerController = mitk::VtkLayerController::GetInstance(m_RenderWindow);
117 
118  if (layerController)
119  {
120  layerController->RemoveRenderer(m_Renderer);
121  }
122 
123  m_IsEnabled = false;
124  }
125 }
126 
132 {
133  return m_IsEnabled;
134 }
135 
137 {
138  // nothing to do
139 }
140 
142 {
143  return false;
144 }
145 
147 {
148  return true;
149 }
150 
151 void mitk::VtkWidgetRendering::SetRequestedRegion(const itk::DataObject *)
152 {
153  // nothing to do
154 }
155 
156 void mitk::VtkWidgetRendering::SetVtkWidget(vtkInteractorObserver *widget)
157 {
158  m_VtkWidget = widget;
159 }
160 
161 vtkInteractorObserver *mitk::VtkWidgetRendering::GetVtkWidget() const
162 {
163  return m_VtkWidget;
164 }
void InsertForegroundRenderer(vtkSmartPointer< vtkRenderer > renderer, bool forceAbsoluteForeground)
static VtkLayerController * GetInstance(vtkSmartPointer< vtkRenderWindow > renWin)
vtkInteractorObserver * GetVtkWidget() const
virtual vtkRenderWindow * GetRenderWindow()
virtual void SetRequestedRegion(const itk::DataObject *) override
virtual bool VerifyRequestedRegion() override
void SetVtkWidget(vtkInteractorObserver *widget)
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override
virtual void SetRenderWindow(vtkRenderWindow *renderWindow)
void RemoveRenderer(vtkSmartPointer< vtkRenderer > renderer)
virtual void SetRequestedRegionToLargestPossibleRegion() override
virtual vtkRenderer * GetVtkRenderer()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.