Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkNodeUidMapper.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 mitkNodeUidMapper_h
14 #define mitkNodeUidMapper_h
15 
16 #include <mitkDataStorage.h>
17 #include <mitkDataNode.h>
18 
19 #include <unordered_map>
20 #include <mutex>
21 #include <string>
22 #include <optional>
23 #include <atomic>
24 
25 #include <MitkRESTAPIExports.h>
26 
27 namespace mitk
28 {
45  {
46  public:
48  static constexpr const char* UID_PROPERTY_KEY = "restapi.uid";
49 
52 
55 
56  NodeUidMapper(const NodeUidMapper&) = delete;
60 
70  void SetDataStorage(DataStorage* dataStorage);
71 
78 
90  std::string GetOrCreateUid(DataNode* node);
91 
102  DataNode::Pointer FindNodeByUid(const std::string& uid) const;
103 
111  std::optional<std::string> GetUid(const DataNode* node) const;
112 
119  bool HasUid(const std::string& uid) const;
120 
132  void RestoreUid(const DataNode* node, const std::string& uid);
133 
134  private:
135  void OnNodeAdded(const DataNode* node);
136  void OnNodeRemoved(const DataNode* node);
137  std::string GenerateUid();
138  void ClearRESTUIDProperty();
139 
140  mitk::WeakPointer<DataStorage> m_DataStorage;
141 
142  // Thread-safe UID mappings
143  mutable std::mutex m_Mutex;
144  std::unordered_map<std::string, mitk::WeakPointer<DataNode>> m_UidToNode;
145  std::unordered_map<const DataNode*, std::string> m_NodeToUid;
146 
147  // Counter for unique ID generation (never reused in session)
148  std::atomic<uint64_t> m_UidCounter{0};
149 
150  // Track if we're connected
151  bool m_Connected = false;
152  };
153 }
154 
155 #endif
#define MITKRESTAPI_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.
Maintains transient UID-to-DataNode mappings for the REST API.
void SetDataStorage(DataStorage *dataStorage)
Connect to a DataStorage and start tracking nodes.
NodeUidMapper & operator=(NodeUidMapper &&)=delete
DataNode::Pointer FindNodeByUid(const std::string &uid) const
Find a node by its UID.
NodeUidMapper()
Default constructor.
NodeUidMapper(NodeUidMapper &&)=delete
NodeUidMapper(const NodeUidMapper &)=delete
bool HasUid(const std::string &uid) const
Check whether a UID exists in the mapping.
std::optional< std::string > GetUid(const DataNode *node) const
Get the UID for a node without creating one.
std::string GetOrCreateUid(DataNode *node)
Get or create a UID for the given node.
void RestoreUid(const DataNode *node, const std::string &uid)
Restore a previously assigned UID mapping for a node.
void ClearDataStorage()
Disconnect from the current DataStorage.
NodeUidMapper & operator=(const NodeUidMapper &)=delete
~NodeUidMapper()
Destructor. Disconnects from the DataStorage if connected.
A weak pointer that observes an itk::Object without preventing its deletion.
Find image slices visible on a given plane.