Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (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 mitkToolManager_h_Included
14 #define mitkToolManager_h_Included
15 
16 #include "mitkDataNode.h"
17 #include "mitkDataStorage.h"
18 #include "mitkTool.h"
19 #include "mitkWeakPointer.h"
21 
22 #pragma GCC visibility push(default)
23 #include <itkEventObject.h>
24 #pragma GCC visibility pop
25 
26 #include <vector>
27 
28 namespace mitk
29 {
30  class Image;
31  class PlaneGeometry;
32 
82  class MITKSEGMENTATION_EXPORT ToolManager : public itk::Object
83  {
84  public:
85  typedef std::vector<Tool::Pointer> ToolVectorType;
86  typedef std::vector<Tool::ConstPointer> ToolVectorTypeConst;
87  typedef std::vector<DataNode *> DataVectorType; // has to be observed for delete events!
88  typedef std::map<DataNode *, unsigned long> NodeTagMapType;
89 
93 
98 
101 
102  mitkClassMacroItkParent(ToolManager, itk::Object);
104 
109  const ToolVectorTypeConst GetTools();
110 
111  int GetToolID(const Tool *tool);
112 
113  /*
114  \param id The tool of interest.
115  Counting starts with 0.
116  */
117  Tool *GetToolById(int id);
118 
124  bool ActivateTool(int id);
125 
126  template <class T>
128  {
129  int id = 0;
130  for (auto iter = m_Tools.begin(); iter != m_Tools.end(); ++iter, ++id)
131  {
132  if (dynamic_cast<T *>(iter->GetPointer()))
133  {
134  return id;
135  }
136  }
137  return -1;
138  }
139 
143  int GetActiveToolID();
144 
148  Tool *GetActiveTool();
149 
150  /*
151  \brief Set a list of data/images as reference objects.
152  */
153  void SetReferenceData(DataVectorType);
154 
155  /*
156  \brief Set single data item/image as reference object.
157  */
158  void SetReferenceData(DataNode *);
159 
160  /*
161  \brief Set a list of data/images as working objects.
162  */
163  void SetWorkingData(DataVectorType);
164 
165  /*
166  \brief Set single data item/image as working object.
167  */
168  void SetWorkingData(DataNode *);
169 
170  /*
171  \brief Set a list of data/images as roi objects.
172  */
173  void SetRoiData(DataVectorType);
174 
175  /*
176  \brief Set a single data item/image as roi object.
177  */
178  void SetRoiData(DataNode *);
179 
180  /*
181  \brief Get the list of reference data.
182  */
183  DataVectorType GetReferenceData();
184 
185  /*
186  \brief Get the current reference data.
187  \warning If there is a list of items, this method will only return the first list item.
188  */
189  DataNode *GetReferenceData(int);
190 
191  /*
192  \brief Get the list of working data.
193  */
194  DataVectorType GetWorkingData();
195 
196  /*
197  \brief Get the current working data.
198  \warning If there is a list of items, this method will only return the first list item.
199  */
200  DataNode *GetWorkingData(unsigned int);
201 
202  /*
203  \brief Get the current roi data
204  */
205  DataVectorType GetRoiData();
206 
207  /*
208  \brief Get the roi data at position idx
209  */
210  DataNode *GetRoiData(int idx);
211 
212  DataStorage *GetDataStorage();
213  void SetDataStorage(DataStorage &storage);
214 
215  /*
216  \brief Tell that someone is using tools.
217  GUI elements should call this when they become active. This method increases an internal "client count".
218  */
219  void RegisterClient();
220 
221  /*
222  \brief Tell that someone is NOT using tools.
223  GUI elements should call this when they become active. This method increases an internal "client count".
224  */
225  void UnregisterClient();
226 
228  void InitializeTools();
229 
230  void OnOneOfTheReferenceDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
231  void OnOneOfTheReferenceDataDeleted(itk::Object *caller, const itk::EventObject &e);
232 
233  void OnOneOfTheWorkingDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
234  void OnOneOfTheWorkingDataDeleted(itk::Object *caller, const itk::EventObject &e);
235 
236  void OnOneOfTheRoiDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
237  void OnOneOfTheRoiDataDeleted(itk::Object *caller, const itk::EventObject &e);
238 
239  /*
240  \brief Connected to tool's messages
241 
242  This method just resends error messages coming from any of the tools. This way clients (GUIs) only have to observe
243  one message.
244  */
245  void OnToolErrorMessage(std::string s);
246  void OnGeneralToolMessage(std::string s);
247 
248  protected:
256  ToolManager(DataStorage *storage); // purposely hidden
257  ~ToolManager() override;
258 
259  ToolVectorType m_Tools;
260 
264 
265  DataVectorType m_ReferenceData;
267 
268  DataVectorType m_WorkingData;
270 
271  DataVectorType m_RoiData;
272  NodeTagMapType m_RoiDataObserverTags;
273 
275 
277 
279  void OnNodeRemoved(const mitk::DataNode *node);
280  };
281 
282 } // namespace
283 
284 #endif
std::vector< Tool::ConstPointer > ToolVectorTypeConst
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:86
Data management class that handles &#39;was created by&#39; relations.
DataVectorType m_WorkingData
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:72
Message WorkingDataChanged
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
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:49
us::ServiceRegistration< InteractionEventObserver > m_ActiveToolRegistration
Event/message/notification class.
Definition: mitkMessage.h:568
NodeTagMapType m_WorkingDataObserverTags
ToolVectorType m_Tools
DataVectorType m_RoiData
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
Manages and coordinates instances of mitk::Tool.