Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkDicomRTIOMimeTypes.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 "mitkDicomRTIOMimeTypes.h"
14 
15 #include "mitkIOMimeTypes.h"
16 
18 #include "mitkDICOMTagPath.h"
20 #include <mitkDICOMFileReader.h>
21 
22 #include <itksys/SystemTools.hxx>
23 
24 #include <usModuleContext.h>
25 #include <usGetModuleContext.h>
26 #include <usServiceProperties.h>
27 #include <usServiceRegistration.h>
28 
29 namespace mitk
30 {
31 
32 std::vector<CustomMimeType*> DicomRTIOMimeTypes::Get()
33 {
34  std::vector<CustomMimeType*> mimeTypes;
35 
36  // order matters here (descending rank for mime types)
37  mimeTypes.push_back(DICOMRT_DOSE_MIMETYPE().Clone());
38  mimeTypes.push_back(DICOMRT_PLAN_MIMETYPE().Clone());
39  mimeTypes.push_back(DICOMRT_STRUCT_MIMETYPE().Clone());
40 
41  return mimeTypes;
42 }
43 
44 // Mime Types
45 
48 {
49  std::string category = "DICOMRT";
50  this->SetCategory(category);
51  this->SetComment("RTDose");
52 
53  this->AddExtension("dcm");
54 }
55 
56 bool DicomRTIOMimeTypes::RTDoseMimeType::AppliesTo(const std::string &path) const
57 {
58  bool canRead( CustomMimeType::AppliesTo(path) );
59 
60  if (!canRead) {
61  return false;
62  }
63 
64  if (!canReadByDicomFileReader(path)) {
65  return false;
66  }
67 
68  auto modality = GetModality(path);
69 
70  if (modality == "RTDOSE") {
71  return true;
72  }
73  else {
74  return false;
75  }
76 }
77 
78 std::string DicomRTIOMimeTypes::GetModality(const std::string & path)
79 {
81 
82  auto tagsOfInterest = toiSrv->GetTagsOfInterest();
83 
84  DICOMTagPathList tagsOfInterestList;
85  for (const auto& tag : tagsOfInterest) {
86  tagsOfInterestList.push_back(tag.first);
87  }
88 
89  mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New();
90  scanner->SetInputFiles({ path });
91  scanner->AddTagPaths(tagsOfInterestList);
92  scanner->Scan();
93 
94  mitk::DICOMDatasetAccessingImageFrameList frames = scanner->GetFrameInfoList();
95  std::string modality = "";
96  if (frames.empty())
97  return modality;
98  auto findings = frames.front()->GetTagValueAsString(DICOMTagPath(0x0008, 0x0060));
99 
100  modality = findings.front().value;
101  return modality;
102 }
103 
104 bool DicomRTIOMimeTypes::canReadByDicomFileReader(const std::string & filename)
105 {
106  mitk::DICOMFileReaderSelector::Pointer selector = mitk::DICOMFileReaderSelector::New();
107  selector->LoadBuiltIn3DConfigs();
108  selector->SetInputFiles({ filename });
109 
110  mitk::DICOMFileReader::Pointer reader = selector->GetFirstReaderWithMinimumNumberOfOutputImages();
111 
112  if (reader.IsNull()) {
113  return false;
114  }
115  else {
116  return true;
117  }
118 }
119 
121 {
122  return new RTDoseMimeType(*this);
123 }
124 
127 {
128  std::string category = "DICOMRT";
129  this->SetCategory(category);
130  this->SetComment("RTStruct");
131 
132  this->AddExtension("dcm");
133 }
134 
135 bool DicomRTIOMimeTypes::RTStructMimeType::AppliesTo(const std::string &path) const
136 {
137  bool canRead(CustomMimeType::AppliesTo(path));
138 
139  if (!canRead) {
140  return false;
141  }
142 
143  auto modality = GetModality(path);
144  if (modality == "RTSTRUCT") {
145  return true;
146  }
147  else {
148  return false;
149  }
150 }
151 
153 {
154  return new RTStructMimeType(*this);
155 }
156 
159 {
160  std::string category = "DICOMRT";
161  this->SetCategory(category);
162  this->SetComment("RTPLAN");
163 
164  this->AddExtension("dcm");
165 }
166 
167 bool DicomRTIOMimeTypes::RTPlanMimeType::AppliesTo(const std::string &path) const
168 {
169  bool canRead(CustomMimeType::AppliesTo(path));
170 
171  if (!canRead) {
172  return false;
173  }
174 
175  auto modality = GetModality(path);
176  if (modality == "RTPLAN") {
177  return true;
178  }
179  else {
180  return false;
181  }
182 }
183 
185 {
186  return new RTPlanMimeType(*this);
187 }
188 
189 
191 {
192  return RTDoseMimeType();
193 }
194 
196 {
197  return RTStructMimeType();
198 }
199 
201 {
202  return RTPlanMimeType();
203 }
204 
205 // Names
207 {
208  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.dose";
209  return name;
210 }
211 
213 {
214  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.struct";
215  return name;
216 }
217 
219 {
220  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.plan";
221  return name;
222 }
223 
224 // Descriptions
225 
227 {
228  static std::string description = "RTDOSE reader";
229  return description;
230 }
231 
233 {
234  static std::string description = "RTSTRUCT reader";
235  return description;
236 }
237 
239 {
240  static std::string description = "RTPLAN reader";
241  return description;
242 }
243 
245 {
246  mitk::IDICOMTagsOfInterest* result = nullptr;
247 
248  std::vector<us::ServiceReference<mitk::IDICOMTagsOfInterest> > toiRegisters = us::GetModuleContext()->GetServiceReferences<mitk::IDICOMTagsOfInterest>();
249  if (!toiRegisters.empty())
250  {
251  if (toiRegisters.size() > 1)
252  {
253  MITK_WARN << "Multiple DICOM tags of interest services found. Using just one.";
254  }
255  result = us::GetModuleContext()->GetService<mitk::IDICOMTagsOfInterest>(toiRegisters.front());
256  }
257 
258  return result;
259 }
260 
261 }
static std::string GetModality(const std::string &path)
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
static std::string DICOMRT_STRUCT_MIMETYPE_DESCRIPTION()
DataCollection - Class to facilitate loading/accessing structured data.
static RTDoseMimeType DICOMRT_DOSE_MIMETYPE()
virtual bool AppliesTo(const std::string &path) const
Checks if the MimeType can handle file at the given location.
static std::string DICOMRT_PLAN_MIMETYPE_DESCRIPTION()
void SetComment(const std::string &comment)
Interface of DICOM tags of interest service.
void * GetService(const ServiceReferenceBase &reference)
static std::string DICOMRT_PLAN_MIMETYPE_NAME()
static RTPlanMimeType DICOMRT_PLAN_MIMETYPE()
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static std::string DEFAULT_BASE_NAME()
#define MITK_WARN
Definition: mitkLogMacros.h:19
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
static bool canReadByDicomFileReader(const std::string &path)
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
static mitk::IDICOMTagsOfInterest * GetDicomTagsOfInterestService()
void AddExtension(const std::string &extension)
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
std::vector< DICOMTagPath > DICOMTagPathList
static std::vector< CustomMimeType * > Get()
void SetCategory(const std::string &category)
static RTStructMimeType DICOMRT_STRUCT_MIMETYPE()
std::vector< DICOMDatasetAccessingImageFrameInfo::Pointer > DICOMDatasetAccessingImageFrameList
RTStructMimeType * Clone() const override
static std::string DICOMRT_DOSE_MIMETYPE_DESCRIPTION()
virtual DICOMTagPathMapType GetTagsOfInterest() const =0
static mitk::PlanarFigure::Pointer Clone(mitk::PlanarFigure::Pointer original)
static std::string DICOMRT_STRUCT_MIMETYPE_NAME()
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
static std::string DICOMRT_DOSE_MIMETYPE_NAME()