Medical Imaging Interaction Toolkit  2026.06.00
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 #ifdef __GNUC__
24 #pragma GCC visibility push(default)
25 #endif
26 #include <itkEventObject.h>
27 #ifdef __GNUC__
28 #pragma GCC visibility pop
29 #endif
30 
31 #include <vector>
32 
33 namespace mitk
34 {
35  class Image;
36  class PlaneGeometry;
37 
83  class MITKSEGMENTATION_EXPORT ToolManager : public itk::Object
84  {
85  public:
86  typedef std::vector<Tool::Pointer> ToolVectorType;
87  typedef std::vector<Tool::ConstPointer> ToolVectorTypeConst;
88  typedef std::vector<DataNode *> DataVectorType; // has to be observed for delete events!
89  typedef std::map<DataNode *, unsigned long> NodeTagMapType;
90 
94 
100 
102 
105 
108 
114 
120  int GetToolID(const Tool *tool);
121 
126  Tool *GetToolById(int id);
127 
133  bool ActivateTool(int id);
134 
140  template <class T>
142  {
143  int id = 0;
144  for (auto iter = m_Tools.begin(); iter != m_Tools.end(); ++iter, ++id)
145  {
146  if (dynamic_cast<T *>(iter->GetPointer()))
147  {
148  return id;
149  }
150  }
151  return -1;
152  }
153 
158 
163 
168 
173 
178 
183 
188 
193 
198 
203 
209 
214 
219  DataNode *GetWorkingData(unsigned int);
220 
225 
229  DataNode *GetRoiData(int idx);
230 
235 
237  DataStorage::Pointer GetDataStorage() const;
238 
243  void SetDataStorage(DataStorage &storage);
244 
248 
254 
260 
263 
264  void OnOneOfTheReferenceDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
265  void OnOneOfTheReferenceDataDeleted(itk::Object *caller, const itk::EventObject &e);
266 
267  void OnOneOfTheWorkingDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
268  void OnOneOfTheWorkingDataDeleted(itk::Object *caller, const itk::EventObject &e);
269 
270  void OnOneOfTheRoiDataDeletedConst(const itk::Object *caller, const itk::EventObject &e);
271  void OnOneOfTheRoiDataDeleted(itk::Object *caller, const itk::EventObject &e);
272 
279  void OnToolErrorMessage(std::string s);
280  void OnGeneralToolMessage(std::string s);
281 
282  protected:
290  ToolManager(DataStorage *storage); // purposely hidden
291  ~ToolManager() override;
292 
294 
298 
301 
304 
307 
309 
311 
313 
315  void OnNodeRemoved(const mitk::DataNode *node);
316 
318  void OnTimeChangedConst(const itk::Object* caller, const itk::EventObject& e);
319  void OnTimeChanged(itk::Object* caller, const itk::EventObject& e);
320 
323 
324  private:
326  TimePointType m_LastTimePoint = 0;
328  unsigned long m_TimePointObserverTag = 0;
330  WeakPointer<TimeNavigationController> m_CurrentTimeNavigationController;
331  };
332 
333 } // namespace
334 
335 #endif
#define MITKSEGMENTATION_EXPORT
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
Abstract data management class that organizes DataNode objects in a directed acyclic graph.
Event/message/notification class.
Definition: mitkMessage.h:521
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
Returns the data storage associated with this tool manager.
void OnOneOfTheWorkingDataDeleted(itk::Object *caller, const itk::EventObject &e)
ToolVectorType m_Tools
int GetToolID(const Tool *tool)
Returns the ID (index) of the given 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.
int GetToolIdByToolType()
Returns the ID (index) of the first tool matching the given type.
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)
Sets the data storage for this tool manager.
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:80
A weak pointer that observes an itk::Object without preventing its deletion.
class ITK_EXPORT Image
Find image slices visible on a given plane.
mitk::ScalarType TimePointType
Type for time point values in milliseconds (ms).