20 #include <vtkObjectFactory.h>
21 #include <vtkRenderWindow.h>
22 #include <vtkRenderer.h>
23 #include <vtkRendererCollection.h>
25 mitk::VtkLayerController::vtkLayerControllerMapType mitk::VtkLayerController::s_LayerControllerMap;
29 for (
auto mapit = s_LayerControllerMap.begin(); mapit != s_LayerControllerMap.end(); ++mapit)
31 if ((*mapit).first == renWin)
32 return (*mapit).second;
38 vtkSmartPointer<vtkRenderer> mitkSceneRenderer)
47 s_LayerControllerMap.insert(vtkLayerControllerMapType::value_type(renWin, ControllerInstance));
52 auto mapit = s_LayerControllerMap.find(renWin);
53 if (mapit != s_LayerControllerMap.end())
56 s_LayerControllerMap.erase(mapit);
62 m_RenderWindow = renderWindow;
63 m_RenderWindow->Register(
nullptr);
64 m_BackgroundRenderers.clear();
65 m_ForegroundRenderers.clear();
66 m_SceneRenderers.clear();
71 if (m_RenderWindow !=
nullptr)
73 m_RenderWindow->UnRegister(
nullptr);
83 bool forceAbsoluteBackground)
85 if (renderer ==
nullptr)
89 RemoveRenderer(renderer);
91 if (forceAbsoluteBackground)
93 auto it = m_BackgroundRenderers.begin();
94 m_BackgroundRenderers.insert(it, renderer);
97 m_BackgroundRenderers.push_back(renderer);
106 bool forceAbsoluteForeground)
108 if (renderer ==
nullptr)
112 RemoveRenderer(renderer);
114 if (forceAbsoluteForeground)
116 auto it = m_ForegroundRenderers.begin();
117 m_ForegroundRenderers.insert(it, renderer);
120 m_ForegroundRenderers.push_back(renderer);
122 renderer->PreserveDepthBufferOn();
130 if (m_SceneRenderers.size() > 0)
132 auto it = m_SceneRenderers.begin();
144 if (renderer ==
nullptr)
148 RemoveRenderer(renderer);
150 m_SceneRenderers.push_back(renderer);
159 RendererVectorType::iterator it;
161 if (m_BackgroundRenderers.size() > 0)
163 it = std::find(m_BackgroundRenderers.begin(), m_BackgroundRenderers.end(), renderer);
164 if (it != m_BackgroundRenderers.end())
166 m_BackgroundRenderers.erase(it);
172 if (m_SceneRenderers.size() > 0)
174 it = std::find(m_SceneRenderers.begin(), m_SceneRenderers.end(), renderer);
175 if (it != m_SceneRenderers.end())
177 m_SceneRenderers.erase(it);
183 if (m_ForegroundRenderers.size() > 0)
185 it = std::find(m_ForegroundRenderers.begin(), m_ForegroundRenderers.end(), renderer);
186 if (it != m_ForegroundRenderers.end())
188 m_ForegroundRenderers.erase(it);
199 if (renwin !=
nullptr)
201 RendererVectorType::iterator it;
203 for (it = m_BackgroundRenderers.begin(); it != m_BackgroundRenderers.end(); ++it)
205 (*it)->SetRenderWindow(renwin);
207 for (it = m_SceneRenderers.begin(); it != m_SceneRenderers.end(); ++it)
209 (*it)->SetRenderWindow(renwin);
211 for (it = m_ForegroundRenderers.begin(); it != m_ForegroundRenderers.end(); ++it)
213 (*it)->SetRenderWindow(renwin);
216 m_RenderWindow = renwin;
227 RendererVectorType::iterator it;
229 if (m_BackgroundRenderers.size() > 0)
231 it = std::find(m_BackgroundRenderers.begin(), m_BackgroundRenderers.end(), renderer);
232 if (it != m_BackgroundRenderers.end())
238 if (m_SceneRenderers.size() > 0)
240 it = std::find(m_SceneRenderers.begin(), m_SceneRenderers.end(), renderer);
241 if (it != m_SceneRenderers.end())
247 if (m_ForegroundRenderers.size() > 0)
249 it = std::find(m_ForegroundRenderers.begin(), m_ForegroundRenderers.end(), renderer);
250 if (it != m_ForegroundRenderers.end())
262 void mitk::VtkLayerController::UpdateLayers()
265 vtkSmartPointer<vtkRendererCollection> v = m_RenderWindow->GetRenderers();
268 unsigned int numberOfLayers =
269 static_cast<unsigned int>(m_BackgroundRenderers.size() + m_SceneRenderers.size() + m_ForegroundRenderers.size());
270 int currentLayerNumber;
271 bool traverseUpwards;
273 currentLayerNumber = 0;
274 traverseUpwards =
true;
276 m_RenderWindow->SetNumberOfLayers(numberOfLayers);
277 RendererVectorType::iterator it;
279 for (it = m_BackgroundRenderers.begin(); it != m_BackgroundRenderers.end(); ++it)
281 (*it)->SetRenderWindow(m_RenderWindow);
282 (*it)->SetLayer(currentLayerNumber);
283 m_RenderWindow->AddRenderer((*it));
286 currentLayerNumber++;
288 currentLayerNumber--;
291 for (it = m_SceneRenderers.begin(); it != m_SceneRenderers.end(); ++it)
293 (*it)->SetRenderWindow(m_RenderWindow);
294 (*it)->SetLayer(currentLayerNumber);
295 m_RenderWindow->AddRenderer((*it));
298 currentLayerNumber++;
300 currentLayerNumber--;
303 for (it = m_ForegroundRenderers.begin(); it != m_ForegroundRenderers.end(); ++it)
305 (*it)->SetRenderWindow(m_RenderWindow);
306 (*it)->SetLayer(currentLayerNumber);
307 m_RenderWindow->AddRenderer((*it));
310 currentLayerNumber++;
312 currentLayerNumber--;
320 return static_cast<unsigned int>(m_BackgroundRenderers.size() + m_SceneRenderers.size() +
321 m_ForegroundRenderers.size());
326 this->m_RenderWindow->SetErase(i);
328 RendererVectorType::iterator it;
329 for (it = m_BackgroundRenderers.begin(); it != m_BackgroundRenderers.end(); ++it)
332 for (it = m_SceneRenderers.begin(); it != m_SceneRenderers.end(); ++it)
335 for (it = m_ForegroundRenderers.begin(); it != m_ForegroundRenderers.end(); ++it)
void SetEraseForAllRenderers(int i)
void InsertSceneRenderer(vtkSmartPointer< vtkRenderer > renderer)
void InsertForegroundRenderer(vtkSmartPointer< vtkRenderer > renderer, bool forceAbsoluteForeground)
static void AddInstance(vtkSmartPointer< vtkRenderWindow > renWin, vtkSmartPointer< vtkRenderer > mitkSceneRenderer)
static VtkLayerController * GetInstance(vtkSmartPointer< vtkRenderWindow > renWin)
void SetRenderWindow(vtkSmartPointer< vtkRenderWindow > renwin)
virtual ~VtkLayerController()
VtkLayerController(vtkSmartPointer< vtkRenderWindow > renderWindow)
vtkSmartPointer< vtkRenderer > GetSceneRenderer()
void RemoveRenderer(vtkSmartPointer< vtkRenderer > renderer)
bool IsRendererInserted(vtkSmartPointer< vtkRenderer > renderer)
unsigned int GetNumberOfRenderers()
void InsertBackgroundRenderer(vtkSmartPointer< vtkRenderer > renderer, bool forceAbsoluteBackground)
static void RemoveInstance(vtkSmartPointer< vtkRenderWindow > renWin)