Medical Imaging Interaction Toolkit  2025.12.02
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
14 #define mitkToolManager_h
15 
16 #include "mitkDataNode.h"
17 #include "mitkDataStorage.h"
18 #include "mitkTool.h"
19 #include "mitkWeakPointer.h"
21 #include <mitkLabelSetImage.h>
22 
23 #pragma GCC visibility push(default)
24 #include <itkEventObject.h>
25 #pragma GCC visibility pop
26 
27 #include <vector>
28 
29 namespace mitk
30 {
31  class Image;
32  class PlaneGeometry;
33 
79  class MITKSEGMENTATION_EXPORT ToolManager : public itk::Object
80  {
81  public:
82  typedef std::vector<Tool::Pointer> ToolVectorType;
83  typedef std::vector<Tool::ConstPointer> ToolVectorTypeConst;
84  typedef std::vector<DataNode *> DataVectorType; // has to be observed for delete events!
85  typedef std::map<DataNode *, unsigned long> NodeTagMapType;
86 
90 
96 
98 
101 
104 
110 
111  int GetToolID(const Tool *tool);
112 
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 
144 
149 
154 
159 
164 
169 
174 
179 
184 
189 
195 
200 
205  DataNode *GetWorkingData(unsigned int);
206 
211 
215  DataNode *GetRoiData(int idx);
216 
221 
222  DataStorage::Pointer GetDataStorage() const;
223  void SetDataStorage(DataStorage &storage);
224 
228 
234 
240 
243 
244  void OnOneOfTheReferenceDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
245  void OnOneOfTheReferenceDataDeleted(itk::Object *caller, const itk::EventObject &e);
246 
247  void OnOneOfTheWorkingDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
248  void OnOneOfTheWorkingDataDeleted(itk::Object *caller, const itk::EventObject &e);
249 
250  void OnOneOfTheRoiDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
251  void OnOneOfTheRoiDataDeleted(itk::Object *caller, const itk::EventObject &e);
252 
259  void OnToolErrorMessage(std::string s);
260  void OnGeneralToolMessage(std::string s);
261 
262  protected:
270  ToolManager(DataStorage *storage); // purposely hidden
271  ~ToolManager() override;
272 
274 
278 
281 
284 
287 
289 
291 
293 
295  void OnNodeRemoved(const mitk::DataNode *node);
296 
298  void OnTimeChangedConst(const itk::Object* caller, const itk::EventObject& e);
299  void OnTimeChanged(itk::Object* caller, const itk::EventObject& e);
300 
303 
304  private:
306  TimePointType m_LastTimePoint = 0;
308  unsigned long m_TimePointObserverTag = 0;
310  WeakPointer<TimeNavigationController> m_CurrentTimeNavigationController;
311  };
312 
313 } // namespace
314 
315 #endif
#define MITKSEGMENTATION_EXPORT
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Data management class that handles 'was created by' relations.
Event/message/notification class.
Definition: mitkMessage.h:453
mitk::Label::PixelType LabelValueType
Manages and coordinates instances of mitk::Tool.
void InitializeTools()
Initialize all classes derived from mitk::Tool by itkObjectFactoy.
DataNode * GetRoiData(int idx)
Get the roi data at position idx.
Message1< std::string > GeneralToolMessage
void OnTimeChanged(itk::Object *caller, const itk::EventObject &e)
mitkClassMacroItkParent(ToolManager, itk::Object)
Tool * GetActiveTool()
DataVectorType m_ReferenceData
void OnNodeRemoved(const mitk::DataNode *node)
Callback for NodeRemove events.
Message1< std::string > ToolErrorMessage
DataStorage::Pointer GetDataStorage() const
void OnOneOfTheWorkingDataDeleted(itk::Object *caller, const itk::EventObject &e)
ToolVectorType m_Tools
int GetToolID(const Tool *tool)
void SetActiveWorkingLabel(MultiLabelSegmentation::LabelValueType labelValue)
Set the active label value for the current working data.
Message SelectedTimePointChanged
void SetRoiData(DataVectorType)
Set a list of data/images as roi objects.
MultiLabelSegmentation::LabelValueType m_ActiveWorkingLabel
DataNode * GetReferenceData(int)
Get the current reference data.
Message WorkingDataChanged
void SetRoiData(DataNode *)
Set a single data item/image as roi object.
void OnOneOfTheReferenceDataDeleted(itk::Object *caller, const itk::EventObject &e)
DataVectorType m_WorkingData
Tool * GetToolById(int id)
DataVectorType m_RoiData
void SetWorkingData(DataNode *)
Set single data item/image as working object.
WeakPointer< DataStorage > m_DataStorage
NodeTagMapType m_WorkingDataObserverTags
DataVectorType GetRoiData()
Get the current roi data.
DataNode * GetWorkingData(unsigned int)
Get the current working data.
Message NodePropertiesChanged
void OnOneOfTheReferenceDataDeletedConst(const itk::Object *caller, const itk::EventObject &e)
ToolManager(DataStorage *storage)
NodeTagMapType m_RoiDataObserverTags
void SetReferenceData(DataVectorType)
Set a list of data/images as reference objects.
NodeTagMapType m_ReferenceDataObserverTags
const ToolVectorTypeConst GetTools()
Gives you a list of all tools. This is const on purpose.
Message ReferenceDataChanged
std::map< DataNode *, unsigned long > NodeTagMapType
~ToolManager() override
void OnOneOfTheWorkingDataDeletedConst(const itk::Object *caller, const itk::EventObject &e)
void OnGeneralToolMessage(std::string s)
void OnTimeChangedConst(const itk::Object *caller, const itk::EventObject &e)
void StopTimeObservation()
DataVectorType GetReferenceData()
Get the list of reference data.
TimePointType GetCurrentTimePoint() const
MultiLabelSegmentation::LabelValueType GetActiveWorkingLabel()
Get the active label value for the current working data.
void SetReferenceData(DataNode *)
Set single data item/image as reference object.
std::vector< Tool::ConstPointer > ToolVectorTypeConst
void OnOneOfTheRoiDataDeleted(itk::Object *caller, const itk::EventObject &e)
void SetDataStorage(DataStorage &storage)
Message ActiveWorkingLabelChanged
us::ServiceRegistration< InteractionEventObserver > m_ActiveToolRegistration
mitkNewMacro1Param(ToolManager, DataStorage *)
bool ActivateTool(int id)
DataVectorType GetWorkingData()
Get the list of working data.
void SetWorkingData(DataVectorType)
Set a list of data/images as working objects.
std::vector< Tool::Pointer > ToolVectorType
std::vector< DataNode * > DataVectorType
void UnregisterClient()
Tell that someone is NOT using tools. GUI elements should call this when they become active....
Message1< DataVectorType * > NewNodeObjectsGenerated
void OnToolErrorMessage(std::string s)
Connected to tool's messages.
void RegisterClient()
Tell that someone is using tools. GUI elements should call this when they become active....
void EnsureTimeObservation()
void OnOneOfTheRoiDataDeletedConst(const itk::Object *caller, const itk::EventObject &e)
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:79
class ITK_EXPORT Image
Find image slices visible on a given plane.
mitk::ScalarType TimePointType