Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkUIDHelper.h"
18 
19 
20 // Mitk
21 #include <mitkUIDGenerator.h>
22 #include <mitkExceptionMacro.h>
23 #include <mitkDataNode.h>
24 #include <mitkBaseData.h>
25 
27 {
28  if (!node)
29  {
30  mitkThrow() << "Cannot ensure node UID. Passed node pointer is NULL.";
31  }
32 
33  std::string propUID = "";
34  if (!node->GetStringProperty(mitk::nodeProp_UID,propUID))
35  {
36  mitk::UIDGenerator generator;
37  propUID = generator.GetUID();
38 
39  node->SetStringProperty(mitk::nodeProp_UID,propUID.c_str());
40  }
41 
42  return propUID;
43 };
44 
45 bool mitk::CheckUID(const mitk::DataNode* node, const NodeUIDType& uid)
46 {
47  bool result = false;
48 
49  if (node)
50  {
51  std::string propUID = "";
52  if (node->GetStringProperty(mitk::nodeProp_UID,propUID))
53  {
54  result = propUID == uid;
55  }
56  }
57 
58  return result;
59 };
60 
62 {
63  if (!data)
64  {
65  mitkThrow() << "Cannot ensure node UID. Passed node pointer is NULL.";
66  }
67 
69  std::string propUID = "";
70 
71  if (uidProp.IsNotNull())
72  {
73  propUID = uidProp->GetValueAsString();
74  }
75  else
76  {
77  mitk::UIDGenerator generator;
78  propUID = generator.GetUID();
79 
81  }
82 
83  return propUID;
84 };
85 
86 bool mitk::CheckUID(const mitk::BaseData* data, const NodeUIDType& uid)
87 {
88  bool result = false;
89 
91 
92  if (uidProp.IsNotNull())
93  {
94  result = uidProp->GetValueAsString() == uid;
95  }
96 
97  return result;
98 };
Generated unique IDs.
Base of all data objects.
Definition: mitkBaseData.h:39
const char *const Prop_UID
const char *const nodeProp_UID
NodeUIDType MITKMATCHPOINTREGISTRATION_EXPORT EnsureUID(mitk::DataNode *node)
bool GetStringProperty(const char *propertyKey, std::string &string, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for string properties (instances of StringProperty)
void SetProperty(const char *propertyKey, BaseProperty *property)
#define mitkThrow()
std::string NodeUIDType
Definition: mitkUIDHelper.h:30
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)
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;.
static Pointer New()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66