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
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,
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 
18 
19 #include "usModuleContext.h"
20 #include "usGetModuleContext.h"
21 
25 
28 {
29  mitk::IPropertyDescriptions* result = nullptr;
30 
31  std::vector<us::ServiceReference<mitk::IPropertyDescriptions> > descriptionRegisters = us::GetModuleContext()->GetServiceReferences<mitk::IPropertyDescriptions>();
32  if (!descriptionRegisters.empty())
33  {
34  if (descriptionRegisters.size() > 1)
35  {
36  MITK_WARN << "Multiple property description services found. Using just one.";
37  }
38  result = us::GetModuleContext()->GetService<mitk::IPropertyDescriptions>(descriptionRegisters.front());
39  }
40 
41  return result;
42 };
43 
46 {
47  mitk::IPropertyPersistence* result = nullptr;
48 
49  std::vector<us::ServiceReference<mitk::IPropertyPersistence> > persRegisters = us::GetModuleContext()->GetServiceReferences<mitk::IPropertyPersistence>();
50  if (!persRegisters.empty())
51  {
52  if (persRegisters.size() > 1)
53  {
54  MITK_WARN << "Multiple property description services found. Using just one.";
55  }
56  result = us::GetModuleContext()->GetService<mitk::IPropertyPersistence>(persRegisters.front());
57  }
58 
59  return result;
60 };
61 
64 {
65 };
66 
69 {
70 };
71 
72 void
74 AddTagOfInterest(const DICOMTagPath& tagPath, bool makePersistant)
75 {
76  if (tagPath.Size() == 0)
77  {
78  MITK_DEBUG << "Indication for wrong DICOMTagsOfInterestService::AddTagOfInterest() usage. Empty DICOM tag path was passed.";
79  return;
80  }
81 
82  MutexHolder lock(m_Lock);
83  std::string propRegEx = mitk::DICOMTagPathToPropertyRegEx(tagPath);
84  this->m_Tags.insert(tagPath);
85 
87  if (descriptionSrv)
88  {
89  descriptionSrv->AddDescriptionRegEx(propRegEx, "DICOM tag: " + tagPath.GetLastNode().tag.GetName());
90  }
91 
93  if (persSrv && makePersistant)
94  {
96  if (tagPath.IsExplicit())
97  {
98  std::string name = mitk::DICOMTagPathToPropertyName(tagPath);
99  std::string key = name;
100  std::replace(key.begin(), key.end(), '.', '_');
101  info->SetNameAndKey(name, key);
102  }
103  else
104  {
105  std::string key = mitk::DICOMTagPathToPersistenceKeyRegEx(tagPath);
106  std::string keyTemplate = mitk::DICOMTagPathToPersistenceKeyTemplate(tagPath);
107  std::string propTemplate = mitk::DICOMTagPathToPersistenceNameTemplate(tagPath);
108  info->UseRegEx(propRegEx, propTemplate, key, keyTemplate);
109  }
110 
113  persSrv->AddInfo(info);
114  }
115 };
116 
120 {
121  MutexHolder lock(m_Lock);
122  DICOMTagPathMapType result;
123 
124  for (auto tag : this->m_Tags)
125  {
126  result.insert(std::make_pair(tag, ""));
127  }
128 
129  return result;
130 };
131 
132 bool
134 HasTag(const DICOMTagPath& tag) const
135 {
136  return this->m_Tags.find(tag) != this->m_Tags.cend();
137 };
138 
139 void
142 {
143  MutexHolder lock(m_Lock);
144  this->m_Tags.erase(tag);
145  std::string propRegEx = mitk::DICOMTagPathToPropertyRegEx(tag);
146 
148  if (descriptionSrv)
149  {
150  descriptionSrv->RemoveDescription(propRegEx);
151  }
152 
154  if (persSrv)
155  {
156  persSrv->RemoveInfo(propRegEx);
157  }
158 };
159 
160 void
163 {
164  MutexHolder lock(m_Lock);
167 
168  for (const auto& tag : m_Tags)
169  {
170  std::string propRegEx = mitk::DICOMTagPathToPropertyRegEx(tag);
171 
172  if (descriptionSrv)
173  {
174  descriptionSrv->RemoveDescription(propRegEx);
175  }
176 
177  if (persSrv)
178  {
179  persSrv->RemoveInfo(propRegEx);
180  }
181  }
182 
183  this->m_Tags.clear();
184 };
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:26
virtual 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:100
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceNameTemplate(const DICOMTagPath &tagPath)
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyName(const DICOMTagPath &tagPath)
virtual void RemoveTag(const DICOMTagPath &tag) override
Remove specific tag. If it not exists the function will do nothing.
Interface of property descriptions service.
bool IsExplicit() const
PathIndexType Size() const
#define MITK_WARN
Definition: mitkLogMacros.h:23
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPersistenceKeyTemplate(const DICOMTagPath &tagPath)
virtual 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)
virtual DICOMTagPathMapType GetTagsOfInterest() const override
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)
virtual bool HasTag(const DICOMTagPath &tag) const override
std::string GetName() const
Return the name of this tag (e.g. "SeriesDescription" instead of "(0008,103e)")
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
std::map< DICOMTagPath, std::string > DICOMTagPathMapType