Medical Imaging Interaction Toolkit  2023.12.00
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 mitkLocalStorageHandler_h
14 #define mitkLocalStorageHandler_h
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 class vtkWindow;
26 class vtkProp;
27 
28 namespace mitk
29 {
33  {
34  public:
36  virtual void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer = true) = 0;
37  };
38 
47  template <class L>
49  {
50  protected:
51  std::map<mitk::BaseRenderer *, L *> m_BaseRenderer2LS;
52 
53  public:
58  void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer = true) override
59  {
60  // MITK_INFO << "deleting a localstorage on a mapper request";
61  if (unregisterFromBaseRenderer)
62  renderer->UnregisterLocalStorageHandler(this);
63  L *l = m_BaseRenderer2LS[renderer];
64  m_BaseRenderer2LS.erase(renderer);
65  delete l;
66  }
67 
68  std::vector<mitk::BaseRenderer *> GetRegisteredBaseRenderer()
69  {
70  std::vector<mitk::BaseRenderer *> baserenderers;
71  typename std::map<mitk::BaseRenderer *, L *>::iterator it;
72  for (it = m_BaseRenderer2LS.begin(); it != m_BaseRenderer2LS.end(); ++it)
73  {
74  baserenderers.push_back(it->first);
75  }
76  return baserenderers;
77  }
78 
84  {
85  L *l = m_BaseRenderer2LS[forRenderer];
86  if (!l)
87  {
88  // MITK_INFO << "creating new localstorage";
89  l = new L;
90  m_BaseRenderer2LS[forRenderer] = l;
91  forRenderer->RegisterLocalStorageHandler(this);
92  }
93  return l;
94  }
95 
97  {
98  typename std::map<mitk::BaseRenderer *, L *>::iterator it;
99 
100  for (it = m_BaseRenderer2LS.begin(); it != m_BaseRenderer2LS.end(); it++)
101  {
102  (*it).first->UnregisterLocalStorageHandler(this);
103  delete (*it).second;
104  }
105 
106  m_BaseRenderer2LS.clear();
107  }
108  };
109 
110 } // namespace mitk
111 
112 #endif
mitk::LocalStorageHandler::~LocalStorageHandler
~LocalStorageHandler() override
Definition: mitkLocalStorageHandler.h:96
mitkVtkPropRenderer.h
mitk::BaseLocalStorageHandler::ClearLocalStorage
virtual void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer=true)=0
mitk::BaseLocalStorageHandler::~BaseLocalStorageHandler
virtual ~BaseLocalStorageHandler()
Definition: mitkLocalStorageHandler.h:35
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::BaseLocalStorageHandler
Interface for accessing (templated) LocalStorageHandler instances.
Definition: mitkLocalStorageHandler.h:32
mitk::LocalStorageHandler
Templated class for management of LocalStorage implementations in Mappers.
Definition: mitkLocalStorageHandler.h:48
mitk::BaseRenderer::RegisterLocalStorageHandler
void RegisterLocalStorageHandler(BaseLocalStorageHandler *lsh)
MitkCoreExports.h
mitk::LocalStorageHandler::m_BaseRenderer2LS
std::map< mitk::BaseRenderer *, L * > m_BaseRenderer2LS
Definition: mitkLocalStorageHandler.h:51
mitkCommon.h
mitk::LocalStorageHandler::GetRegisteredBaseRenderer
std::vector< mitk::BaseRenderer * > GetRegisteredBaseRenderer()
Definition: mitkLocalStorageHandler.h:68
mitk::LocalStorageHandler::ClearLocalStorage
void ClearLocalStorage(mitk::BaseRenderer *renderer, bool unregisterFromBaseRenderer=true) override
deallocates a local storage for a specific BaseRenderer (if the BaseRenderer is itself deallocating i...
Definition: mitkLocalStorageHandler.h:58
mitkLevelWindow.h
mitk::BaseRenderer
Definition: mitkBaseRenderer.h:56
mitk::LocalStorageHandler::GetLocalStorage
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
Definition: mitkLocalStorageHandler.h:83
mitkBaseRenderer.h
mitk::BaseRenderer::UnregisterLocalStorageHandler
void UnregisterLocalStorageHandler(BaseLocalStorageHandler *lsh)