Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkToolManager.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 mitkToolManager_h_Included
18 #define mitkToolManager_h_Included
19 
20 #include "mitkDataNode.h"
21 #include "mitkDataStorage.h"
22 #include "mitkTool.h"
23 #include "mitkWeakPointer.h"
25 
26 #pragma GCC visibility push(default)
27 #include <itkEventObject.h>
28 #pragma GCC visibility pop
29 
30 #include <vector>
31 
32 namespace mitk
33 {
34  class Image;
35  class PlaneGeometry;
36 
86  class MITKSEGMENTATION_EXPORT ToolManager : public itk::Object
87  {
88  public:
89  typedef std::vector<Tool::Pointer> ToolVectorType;
90  typedef std::vector<Tool::ConstPointer> ToolVectorTypeConst;
91  typedef std::vector<DataNode *> DataVectorType; // has to be observed for delete events!
92  typedef std::map<DataNode *, unsigned long> NodeTagMapType;
93 
97 
102 
105 
106  mitkClassMacroItkParent(ToolManager, itk::Object);
108 
113  const ToolVectorTypeConst GetTools();
114 
115  int GetToolID(const Tool *tool);
116 
117  /*
118  \param id The tool of interest.
119  Counting starts with 0.
120  */
121  Tool *GetToolById(int id);
122 
128  bool ActivateTool(int id);
129 
130  template <class T>
132  {
133  int id = 0;
134  for (auto iter = m_Tools.begin(); iter != m_Tools.end(); ++iter, ++id)
135  {
136  if (dynamic_cast<T *>(iter->GetPointer()))
137  {
138  return id;
139  }
140  }
141  return -1;
142  }
143 
147  int GetActiveToolID();
148 
152  Tool *GetActiveTool();
153 
154  /*
155  \brief Set a list of data/images as reference objects.
156  */
157  void SetReferenceData(DataVectorType);
158 
159  /*
160  \brief Set single data item/image as reference object.
161  */
162  void SetReferenceData(DataNode *);
163 
164  /*
165  \brief Set a list of data/images as working objects.
166  */
167  void SetWorkingData(DataVectorType);
168 
169  /*
170  \brief Set single data item/image as working object.
171  */
172  void SetWorkingData(DataNode *);
173 
174  /*
175  \brief Set a list of data/images as roi objects.
176  */
177  void SetRoiData(DataVectorType);
178 
179  /*
180  \brief Set a single data item/image as roi object.
181  */
182  void SetRoiData(DataNode *);
183 
184  /*
185  \brief Get the list of reference data.
186  */
187  DataVectorType GetReferenceData();
188 
189  /*
190  \brief Get the current reference data.
191  \warning If there is a list of items, this method will only return the first list item.
192  */
193  DataNode *GetReferenceData(int);
194 
195  /*
196  \brief Get the list of working data.
197  */
198  DataVectorType GetWorkingData();
199 
200  /*
201  \brief Get the current working data.
202  \warning If there is a list of items, this method will only return the first list item.
203  */
204  DataNode *GetWorkingData(int);
205 
206  /*
207  \brief Get the current roi data
208  */
209  DataVectorType GetRoiData();
210 
211  /*
212  \brief Get the roi data at position idx
213  */
214  DataNode *GetRoiData(int idx);
215 
217  void SetDataStorage(DataStorage &storage);
218 
219  /*
220  \brief Tell that someone is using tools.
221  GUI elements should call this when they become active. This method increases an internal "client count".
222  */
223  void RegisterClient();
224 
225  /*
226  \brief Tell that someone is NOT using tools.
227  GUI elements should call this when they become active. This method increases an internal "client count".
228  */
229  void UnregisterClient();
230 
232  void InitializeTools();
233 
234  void OnOneOfTheReferenceDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
235  void OnOneOfTheReferenceDataDeleted(itk::Object *caller, const itk::EventObject &e);
236 
237  void OnOneOfTheWorkingDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
238  void OnOneOfTheWorkingDataDeleted(itk::Object *caller, const itk::EventObject &e);
239 
240  void OnOneOfTheRoiDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
241  void OnOneOfTheRoiDataDeleted(itk::Object *caller, const itk::EventObject &e);
242 
243  /*
244  \brief Connected to tool's messages
245 
246  This method just resends error messages coming from any of the tools. This way clients (GUIs) only have to observe
247  one message.
248  */
249  void OnToolErrorMessage(std::string s);
250  void OnGeneralToolMessage(std::string s);
251 
252  protected:
260  ToolManager(DataStorage *storage); // purposely hidden
261  virtual ~ToolManager();
262 
263  ToolVectorType m_Tools;
264 
268 
269  DataVectorType m_ReferenceData;
271 
272  DataVectorType m_WorkingData;
274 
275  DataVectorType m_RoiData;
276  NodeTagMapType m_RoiDataObserverTags;
277 
279 
281 
283  void OnNodeRemoved(const mitk::DataNode *node);
284  };
285 
286 } // namespace
287 
288 #endif
std::vector< Tool::ConstPointer > ToolVectorTypeConst
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:92
Data management class that handles 'was created by' relations.
DataVectorType m_WorkingData
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:76
std::vector< DataNode * > DataVectorType
WeakPointer< DataStorage > m_DataStorage
NodeTagMapType m_RoiDataObserverTags
std::vector< Tool::Pointer > ToolVectorType
#define MITKSEGMENTATION_EXPORT
DataCollection - Class to facilitate loading/accessing structured data.
Message1< std::string > ToolErrorMessage
static mitk::DataStorage::Pointer GetDataStorage()
DataVectorType m_ReferenceData
std::map< DataNode *, unsigned long > NodeTagMapType
Message ReferenceDataChanged
NodeTagMapType m_ReferenceDataObserverTags
Message NodePropertiesChanged
class ITK_EXPORT Image
Message1< std::string > GeneralToolMessage
Message1< DataVectorType * > NewNodeObjectsGenerated
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:53
us::ServiceRegistration< InteractionEventObserver > m_ActiveToolRegistration
Event/message/notification class.
Definition: mitkMessage.h:572
Implements a weak reference to an object.
NodeTagMapType m_WorkingDataObserverTags
ToolVectorType m_Tools
DataVectorType m_RoiData
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
Manages and coordinates instances of mitk::Tool.