Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
mitkModelFitUIDHelper.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 "mitkModelFitUIDHelper.h"
14 
15 
16 // Mitk
17 #include <mitkExceptionMacro.h>
18 #include <mitkModelFitConstants.h>
19 #include <mitkUIDGenerator.h>
20 #include <mitkDataNode.h>
21 #include <mitkBaseData.h>
22 #include <mitkDataStorage.h>
23 #include <mitkPropertyNameHelper.h>
24 
26 {
28 
29  if (storage)
30  {
31  auto nodes = storage->GetAll();
32  for (auto node : *(nodes.GetPointer()))
33  {
34  if (CheckModelFitUID(node, uid))
35  {
36  result = node;
37  break;
38  }
39  }
40  }
41 
42  return result;
43 }
44 
46 {
47  if (!node)
48  {
49  mitkThrow() << "Cannot ensure node UID. Passed node pointer is NULL.";
50  }
51 
52  return EnsureModelFitUID(node->GetData());
53 };
54 
56 {
57  if (!data)
58  {
59  mitkThrow() << "Cannot ensure node UID. Passed node pointer is NULL.";
60  }
61 
63  std::string propUID = "";
64 
65 
66  if (uidProp.IsNotNull())
67  {
68  propUID = uidProp->GetValueAsString();
69  }
70  else
71  {
72  //if the "user" defined UID is not found we will check if there is a DICOM series instance UID and use this value if available.
73  uidProp = data->GetProperty(GeneratePropertyNameForDICOMTag(0x0020, 0x000e).c_str());
74 
75  if (uidProp.IsNotNull())
76  {
77  propUID = uidProp->GetValueAsString();
78  }
79  else
80  {
81  mitk::UIDGenerator generator;
82  propUID = generator.GetUID();
83 
85  }
86  }
87 
88  return propUID;
89 };
90 
91 bool mitk::CheckModelFitUID(const mitk::DataNode* node, const NodeUIDType& uid)
92 {
93  if (node)
94  {
95  return CheckModelFitUID(node->GetData(), uid);
96  }
97 
98  return false;
99 };
100 
101 bool mitk::CheckModelFitUID(const mitk::BaseData* data, const NodeUIDType& uid)
102 {
103  bool result = false;
104 
105  if (data)
106  {
108 
109  if (uidProp.IsNotNull())
110  {
111  result = uidProp->GetValueAsString() == uid;
112  }
113 
114  if (!result)
115  {
116  //if the "user" defined UID does not match, we will check if there is a DICOM series instance UID and use this value for the check.
117  uidProp = data->GetProperty(GeneratePropertyNameForDICOMTag(0x0020, 0x000e).c_str());
118 
119  if (uidProp.IsNotNull())
120  {
121  result = uidProp->GetValueAsString() == uid;
122  }
123  }
124  }
125 
126  return result;
127 };
128 
Data management class that handles &#39;was created by&#39; relations.
bool MITKMODELFIT_EXPORT CheckModelFitUID(const mitk::BaseData *data, const NodeUIDType &uid)
Generated unique IDs.
Base of all data objects.
Definition: mitkBaseData.h:37
DataNode::Pointer MITKMODELFIT_EXPORT GetNodeByModelFitUID(const mitk::DataStorage *storage, const NodeUIDType &uid)
std::string MITKCORE_EXPORT GeneratePropertyNameForDICOMTag(unsigned int group, unsigned int element)
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
virtual SetOfObjects::ConstPointer GetAll() const =0
returns a set of all data objects that are stored in the data storage
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
#define mitkThrow()
NodeUIDType MITKMODELFIT_EXPORT EnsureModelFitUID(mitk::BaseData *data)
static const std::string UID_PROPERTY_NAME()
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;.
static Pointer New()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57