Medical Imaging Interaction Toolkit  2016.11.0
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,
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 #ifndef LOCALSTORAGEHANDLER_H_HEADER_INCLUDED_C1E6EA08
18 #define LOCALSTORAGEHANDLER_H_HEADER_INCLUDED_C1E6EA08
19 
20 #include "mitkBaseRenderer.h"
21 #include "mitkCommon.h"
22 #include "mitkLevelWindow.h"
23 #include "mitkVtkPropRenderer.h"
24 #include <MitkCoreExports.h>
25 
26 #include <itkObject.h>
27 #include <itkWeakPointer.h>
28 
29 // Just included to get VTK version
30 #include <vtkConfigure.h>
31 
32 class vtkWindow;
33 class vtkProp;
34 
35 namespace mitk
36 {
40  {
41  public:
43  virtual void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer = true) = 0;
44  };
45 
54  template <class L>
56  {
57  protected:
58  std::map<mitk::BaseRenderer *, L *> m_BaseRenderer2LS;
59 
60  public:
65  virtual void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer = true) override
66  {
67  // MITK_INFO << "deleting a localstorage on a mapper request";
68  if (unregisterFromBaseRenderer)
69  renderer->UnregisterLocalStorageHandler(this);
70  L *l = m_BaseRenderer2LS[renderer];
71  m_BaseRenderer2LS.erase(renderer);
72  delete l;
73  }
74 
80  {
81  L *l = m_BaseRenderer2LS[forRenderer];
82  if (!l)
83  {
84  // MITK_INFO << "creating new localstorage";
85  l = new L;
86  m_BaseRenderer2LS[forRenderer] = l;
87  forRenderer->RegisterLocalStorageHandler(this);
88  }
89  return l;
90  }
91 
93  {
94  typename std::map<mitk::BaseRenderer *, L *>::iterator it;
95 
96  for (it = m_BaseRenderer2LS.begin(); it != m_BaseRenderer2LS.end(); it++)
97  {
98  (*it).first->UnregisterLocalStorageHandler(this);
99  delete (*it).second;
100  }
101 
102  m_BaseRenderer2LS.clear();
103  }
104  };
105 
106 } // namespace mitk
107 
108 #endif /* LOCALSTORAGEHANDLER_H_HEADER_INCLUDED_C1E6EA08 */
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
Templated class for management of LocalStorage implementations in Mappers.
Organizes the rendering process.
std::map< mitk::BaseRenderer *, L * > m_BaseRenderer2LS
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)
virtual void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer=true) override
deallocates a local storage for a specifc BaseRenderer (if the BaseRenderer is itself deallocating it...
void UnregisterLocalStorageHandler(mitk::BaseLocalStorageHandler *lsh)