Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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"
21 #include <mitkDICOMFileReader.h>
22 
23 #include <itksys/SystemTools.hxx>
24 
25 #include <usModuleContext.h>
26 #include <usGetModuleContext.h>
27 #include <usServiceProperties.h>
28 #include <usServiceRegistration.h>
29 
30 namespace mitk
31 {
32 
33 std::vector<CustomMimeType*> DicomRTIOMimeTypes::Get()
34 {
35  std::vector<CustomMimeType*> mimeTypes;
36 
37  // order matters here (descending rank for mime types)
38  mimeTypes.push_back(DICOMRT_DOSE_MIMETYPE().Clone());
39  mimeTypes.push_back(DICOMRT_PLAN_MIMETYPE().Clone());
40  mimeTypes.push_back(DICOMRT_STRUCT_MIMETYPE().Clone());
41 
42  return mimeTypes;
43 }
44 
45 // Mime Types
46 
49 {
50  std::string category = "DICOMRT";
51  this->SetCategory(category);
52  this->SetComment("RTDose");
53 
54  this->AddExtension("dcm");
55 }
56 
57 bool DicomRTIOMimeTypes::RTDoseMimeType::AppliesTo(const std::string &path) const
58 {
59  bool canRead( CustomMimeType::AppliesTo(path) );
60 
61  if (!canRead) {
62  return false;
63  }
64 
65  if (!canReadByDicomFileReader(path)) {
66  return false;
67  }
68 
69  auto modality = GetModality(path);
70 
71  if (modality == "RTDOSE") {
72  return true;
73  }
74  else {
75  return false;
76  }
77 }
78 
79 std::string DicomRTIOMimeTypes::GetModality(const std::string & path)
80 {
82 
83  auto tagsOfInterest = toiSrv->GetTagsOfInterest();
84 
85  DICOMTagPathList tagsOfInterestList;
86  for (const auto& tag : tagsOfInterest) {
87  tagsOfInterestList.push_back(tag.first);
88  }
89 
90  mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New();
91  scanner->SetInputFiles({ path });
92  scanner->AddTagPaths(tagsOfInterestList);
93  scanner->Scan();
94 
95  mitk::DICOMDatasetAccessingImageFrameList frames = scanner->GetFrameInfoList();
96  std::string modality = "";
97  if (frames.empty())
98  return modality;
99  auto findings = frames.front()->GetTagValueAsString(DICOMTagPath(0x0008, 0x0060));
100 
101  modality = findings.front().value;
102  return modality;
103 }
104 
105 bool DicomRTIOMimeTypes::canReadByDicomFileReader(const std::string & filename)
106 {
107  mitk::DICOMFileReaderSelector::Pointer selector = mitk::DICOMFileReaderSelector::New();
108  selector->LoadBuiltIn3DConfigs();
109  selector->SetInputFiles({ filename });
110 
111  mitk::DICOMFileReader::Pointer reader = selector->GetFirstReaderWithMinimumNumberOfOutputImages();
112 
113  if (reader.IsNull()) {
114  return false;
115  }
116  else {
117  return true;
118  }
119 }
120 
122 {
123  return new RTDoseMimeType(*this);
124 }
125 
128 {
129  std::string category = "DICOMRT";
130  this->SetCategory(category);
131  this->SetComment("RTStruct");
132 
133  this->AddExtension("dcm");
134 }
135 
136 bool DicomRTIOMimeTypes::RTStructMimeType::AppliesTo(const std::string &path) const
137 {
138  bool canRead(CustomMimeType::AppliesTo(path));
139 
140  if (!canRead) {
141  return false;
142  }
143 
144  auto modality = GetModality(path);
145  if (modality == "RTSTRUCT") {
146  return true;
147  }
148  else {
149  return false;
150  }
151 }
152 
154 {
155  return new RTStructMimeType(*this);
156 }
157 
160 {
161  std::string category = "DICOMRT";
162  this->SetCategory(category);
163  this->SetComment("RTPLAN");
164 
165  this->AddExtension("dcm");
166 }
167 
168 bool DicomRTIOMimeTypes::RTPlanMimeType::AppliesTo(const std::string &path) const
169 {
170  bool canRead(CustomMimeType::AppliesTo(path));
171 
172  if (!canRead) {
173  return false;
174  }
175 
176  auto modality = GetModality(path);
177  if (modality == "RTPLAN") {
178  return true;
179  }
180  else {
181  return false;
182  }
183 }
184 
186 {
187  return new RTPlanMimeType(*this);
188 }
189 
190 
192 {
193  return RTDoseMimeType();
194 }
195 
197 {
198  return RTStructMimeType();
199 }
200 
202 {
203  return RTPlanMimeType();
204 }
205 
206 // Names
208 {
209  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.dose";
210  return name;
211 }
212 
214 {
215  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.struct";
216  return name;
217 }
218 
220 {
221  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.plan";
222  return name;
223 }
224 
225 // Descriptions
226 
228 {
229  static std::string description = "RTDOSE reader";
230  return description;
231 }
232 
234 {
235  static std::string description = "RTSTRUCT reader";
236  return description;
237 }
238 
240 {
241  static std::string description = "RTPLAN reader";
242  return description;
243 }
244 
246 {
247  mitk::IDICOMTagsOfInterest* result = nullptr;
248 
249  std::vector<us::ServiceReference<mitk::IDICOMTagsOfInterest> > toiRegisters = us::GetModuleContext()->GetServiceReferences<mitk::IDICOMTagsOfInterest>();
250  if (!toiRegisters.empty())
251  {
252  if (toiRegisters.size() > 1)
253  {
254  MITK_WARN << "Multiple DICOM tags of interest services found. Using just one.";
255  }
256  result = us::GetModuleContext()->GetService<mitk::IDICOMTagsOfInterest>(toiRegisters.front());
257  }
258 
259  return result;
260 }
261 
262 }
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()