Medical Imaging Interaction Toolkit  2018.04.99-aba3194f
Medical Imaging Interaction Toolkit
mitkLocalStorageHandler.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef LOCALSTORAGEHANDLER_H_HEADER_INCLUDED_C1E6EA08
14 #define LOCALSTORAGEHANDLER_H_HEADER_INCLUDED_C1E6EA08
15 
16 #include "mitkBaseRenderer.h"
17 #include "mitkCommon.h"
18 #include "mitkLevelWindow.h"
19 #include "mitkVtkPropRenderer.h"
20 #include <MitkCoreExports.h>
21 
22 #include <itkObject.h>
23 #include <itkWeakPointer.h>
24 
25 // Just included to get VTK version
26 #include <vtkConfigure.h>
27 
28 class vtkWindow;
29 class vtkProp;
30 
31 namespace mitk
32 {
36  {
37  public:
39  virtual void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer = true) = 0;
40  };
41 
50  template <class L>
52  {
53  protected:
54  std::map<mitk::BaseRenderer *, L *> m_BaseRenderer2LS;
55 
56  public:
61  void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer = true) override
62  {
63  // MITK_INFO << "deleting a localstorage on a mapper request";
64  if (unregisterFromBaseRenderer)
65  renderer->UnregisterLocalStorageHandler(this);
66  L *l = m_BaseRenderer2LS[renderer];
67  m_BaseRenderer2LS.erase(renderer);
68  delete l;
69  }
70 
71  std::vector<mitk::BaseRenderer *> GetRegisteredBaseRenderer()
72  {
73  std::vector<mitk::BaseRenderer *> baserenderers;
74  typename std::map<mitk::BaseRenderer *, L *>::iterator it;
75  for (it = m_BaseRenderer2LS.begin(); it != m_BaseRenderer2LS.end(); ++it)
76  {
77  baserenderers.push_back(it->first);
78  }
79  return baserenderers;
80  }
81 
87  {
88  L *l = m_BaseRenderer2LS[forRenderer];
89  if (!l)
90  {
91  // MITK_INFO << "creating new localstorage";
92  l = new L;
93  m_BaseRenderer2LS[forRenderer] = l;
94  forRenderer->RegisterLocalStorageHandler(this);
95  }
96  return l;
97  }
98 
100  {
101  typename std::map<mitk::BaseRenderer *, L *>::iterator it;
102 
103  for (it = m_BaseRenderer2LS.begin(); it != m_BaseRenderer2LS.end(); it++)
104  {
105  (*it).first->UnregisterLocalStorageHandler(this);
106  delete (*it).second;
107  }
108 
109  m_BaseRenderer2LS.clear();
110  }
111  };
112 
113 } // namespace mitk
114 
115 #endif /* LOCALSTORAGEHANDLER_H_HEADER_INCLUDED_C1E6EA08 */
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
std::vector< mitk::BaseRenderer * > GetRegisteredBaseRenderer()
Templated class for management of LocalStorage implementations in Mappers.
Organizes the rendering process.
std::map< mitk::BaseRenderer *, L * > m_BaseRenderer2LS
void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer=true) override
deallocates a local storage for a specifc BaseRenderer (if the BaseRenderer is itself deallocating it...
DataCollection - Class to facilitate loading/accessing structured data.
Interface for accessing (templated) LocalStorageHandler instances.
virtual void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer=true)=0
void RegisterLocalStorageHandler(mitk::BaseLocalStorageHandler *lsh)
void UnregisterLocalStorageHandler(mitk::BaseLocalStorageHandler *lsh)