Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
mitkUIDHelper.cpp
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 #include "mitkUIDHelper.h"
14 
15 
16 // Mitk
17 #include <mitkUIDGenerator.h>
18 #include <mitkExceptionMacro.h>
19 #include <mitkDataNode.h>
20 #include <mitkBaseData.h>
21 
23 {
24  if (!node)
25  {
26  mitkThrow() << "Cannot ensure node UID. Passed node pointer is nullptr.";
27  }
28 
29  std::string propUID = "";
30  if (!node->GetStringProperty(mitk::nodeProp_UID,propUID))
31  {
32  mitk::UIDGenerator generator;
33  propUID = generator.GetUID();
34 
35  node->SetStringProperty(mitk::nodeProp_UID,propUID.c_str());
36  }
37 
38  return propUID;
39 };
40 
41 bool mitk::CheckUID(const mitk::DataNode* node, const NodeUIDType& uid)
42 {
43  bool result = false;
44 
45  if (node)
46  {
47  std::string propUID = "";
48  if (node->GetStringProperty(mitk::nodeProp_UID,propUID))
49  {
50  result = propUID == uid;
51  }
52  }
53 
54  return result;
55 };
56 
58 {
59  if (!data)
60  {
61  mitkThrow() << "Cannot ensure node UID. Passed node pointer is nullptr.";
62  }
63 
65  std::string propUID = "";
66 
67  if (uidProp.IsNotNull())
68  {
69  propUID = uidProp->GetValueAsString();
70  }
71  else
72  {
73  mitk::UIDGenerator generator;
74  propUID = generator.GetUID();
75 
77  }
78 
79  return propUID;
80 };
81 
82 bool mitk::CheckUID(const mitk::BaseData* data, const NodeUIDType& uid)
83 {
84  bool result = false;
85 
87 
88  if (uidProp.IsNotNull())
89  {
90  result = uidProp->GetValueAsString() == uid;
91  }
92 
93  return result;
94 };
Generated unique IDs.
Base of all data objects.
Definition: mitkBaseData.h:37
bool GetStringProperty(const char *propertyKey, std::string &string, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for string properties (instances of StringProperty)
const char *const Prop_UID
const char *const nodeProp_UID
NodeUIDType MITKMATCHPOINTREGISTRATION_EXPORT EnsureUID(mitk::DataNode *node)
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
#define mitkThrow()
std::string NodeUIDType
Definition: mitkUIDHelper.h:26
mitk::BaseProperty::Pointer GetProperty(const char *propertyKey) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList, and set it to this, respectively;.
bool MITKMATCHPOINTREGISTRATION_EXPORT CheckUID(const mitk::DataNode *node, const NodeUIDType &uid)
void SetStringProperty(const char *propertyKey, const char *string, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting string properties (instances of StringProperty)
static Pointer New()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57