Medical Imaging Interaction Toolkit  2018.4.99-6a3ea89d
Medical Imaging Interaction Toolkit
mitkDICOMTagsOfInterestService.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 
14 
15 #include "usModuleContext.h"
16 #include "usGetModuleContext.h"
17 
21 
24 {
25  mitk::IPropertyDescriptions* result = nullptr;
26 
27  std::vector<us::ServiceReference<mitk::IPropertyDescriptions> > descriptionRegisters = us::GetModuleContext()->GetServiceReferences<mitk::IPropertyDescriptions>();
28  if (!descriptionRegisters.empty())
29  {
30  if (descriptionRegisters.size() > 1)
31  {
32  MITK_WARN << "Multiple property description services found. Using just one.";
33  }
34  result = us::GetModuleContext()->GetService<mitk::IPropertyDescriptions>(descriptionRegisters.front());
35  }
36 
37  return result;
38 };
39 
42 {
43  mitk::IPropertyPersistence* result = nullptr;
44 
45  std::vector<us::ServiceReference<mitk::IPropertyPersistence> > persRegisters = us::GetModuleContext()->GetServiceReferences<mitk::IPropertyPersistence>();
46  if (!persRegisters.empty())
47  {
48  if (persRegisters.size() > 1)
49  {
50  MITK_WARN << "Multiple property description services found. Using just one.";
51  }
52  result = us::GetModuleContext()->GetService<mitk::IPropertyPersistence>(persRegisters.front());
53  }
54 
55  return result;
56 };
57 
60 {
61 };
62 
65 {
66 };
67 
68 void
70 AddTagOfInterest(const DICOMTagPath& tagPath, bool makePersistant)
71 {
72  if (tagPath.Size() == 0)
73  {
74  MITK_DEBUG << "Indication for wrong DICOMTagsOfInterestService::AddTagOfInterest() usage. Empty DICOM tag path was passed.";
75  return;
76  }
77 
78  MutexHolder lock(m_Lock);
79  std::string propRegEx = mitk::DICOMTagPathToPropertyRegEx(tagPath);
80  this->m_Tags.insert(tagPath);
81 
83  if (descriptionSrv)
84  {
85  descriptionSrv->AddDescriptionRegEx(propRegEx, "DICOM tag: " + tagPath.GetLastNode().tag.GetName());
86  }
87 
89  if (persSrv && makePersistant)
90  {
92  if (tagPath.IsExplicit())
93  {
94  std::string name = mitk::DICOMTagPathToPropertyName(tagPath);
95  std::string key = name;
96  std::replace(key.begin(), key.end(), '.', '_');
97  info->SetNameAndKey(name, key);
98  }
99  else
100  {
101  std::string key = mitk::DICOMTagPathToPersistenceKeyRegEx(tagPath);
102  std::string keyTemplate = mitk::DICOMTagPathToPersistenceKeyTemplate(tagPath);
103  std::string propTemplate = mitk::DICOMTagPathToPersistenceNameTemplate(tagPath);
104  info->UseRegEx(propRegEx, propTemplate, key, keyTemplate);
105  }
106 
109  persSrv->AddInfo(info);
110  }
111 };
112 
116 {
117  MutexHolder lock(m_Lock);
118  DICOMTagPathMapType result;
119 
120  for (auto tag : this->m_Tags)
121  {
122  result.insert(std::make_pair(tag, ""));
123  }
124 
125  return result;
126 };
127 
128 bool
130 HasTag(const DICOMTagPath& tag) const
131 {
132  return this->m_Tags.find(tag) != this->m_Tags.cend();
133 };
134 
135 void
138 {
139  MutexHolder lock(m_Lock);
140  this->m_Tags.erase(tag);
141  std::string propRegEx = mitk::DICOMTagPathToPropertyRegEx(tag);
142 
144  if (descriptionSrv)
145  {
146  descriptionSrv->RemoveDescription(propRegEx);
147  }
148 
150  if (persSrv)
151  {
152  persSrv->RemoveInfo(propRegEx);
153  }
154 };
155 
156 void
159 {
160  MutexHolder lock(m_Lock);
163 
164  for (const auto& tag : m_Tags)
165  {
166  std::string propRegEx = mitk::DICOMTagPathToPropertyRegEx(tag);
167 
168  if (descriptionSrv)
169  {
170  descriptionSrv->RemoveDescription(propRegEx);
171  }
172 
173  if (persSrv)
174  {
175  persSrv->RemoveInfo(propRegEx);
176  }
177  }
178 
179  this->m_Tags.clear();
180 };
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
MITKCORE_EXPORT::std::string serializeTemporoSpatialStringPropertyToJSON(const mitk::BaseProperty *prop)
virtual void RemoveInfo(const std::string &propertyName)=0
Remove persistence info instances of a specific property name/regex.
virtual void RemoveDescription(const std::string &propertyName, const std::string &className="")=0
Remove description of specific property.
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceKeyRegEx(const DICOMTagPath &tagPath)
mitk::IPropertyDescriptions * GetDescriptionsService()
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
void AddTagOfInterest(const DICOMTagPath &tag, bool makePersistant=true) override
Add an tag to the TOI. If the tag was already added it will be overwritten with the passed values...
void * GetService(const ServiceReferenceBase &reference)
static void info(const char *fmt,...)
Definition: svm.cpp:86
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceNameTemplate(const DICOMTagPath &tagPath)
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyName(const DICOMTagPath &tagPath)
void RemoveTag(const DICOMTagPath &tag) override
Remove specific tag. If it not exists the function will do nothing.
PathIndexType Size() const
Interface of property descriptions service.
#define MITK_WARN
Definition: mitkLogMacros.h:19
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceKeyTemplate(const DICOMTagPath &tagPath)
void RemoveAllTags() override
Remove all tags.
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
Interface of property persistence service.
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyRegEx(const DICOMTagPath &tagPath)
DICOMTagPathMapType GetTagsOfInterest() const override
std::string GetName() const
Return the name of this tag (e.g. "SeriesDescription" instead of "(0008,103e)")
virtual bool AddDescriptionRegEx(const std::string &propertyRegEx, const std::string &description, const std::string &className="", bool overwrite=false)=0
Add a description for all properties matching the property regulary expression.
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
mitk::IPropertyPersistence * GetPersistenceService()
virtual bool AddInfo(const PropertyPersistenceInfo *info, bool overwrite=false)=0
Add persistence info for a specific base data property. If there is already a property info instance ...
MITKCORE_EXPORT mitk::BaseProperty::Pointer deserializeJSONToTemporoSpatialStringProperty(const std::string &value)
bool HasTag(const DICOMTagPath &tag) const override
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
std::map< DICOMTagPath, std::string > DICOMTagPathMapType