Medical Imaging Interaction Toolkit  2018.4.99-a3d2e8fb
Medical Imaging Interaction Toolkit
mitkDicomRTMimeTypes.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 <mitkDicomRTMimeTypes.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::array<std::unique_ptr<CustomMimeType>, 3> DicomRTMimeTypes::Get()
33 {
34  return {
35  std::make_unique<RTDoseMimeType>(),
36  std::make_unique<RTPlanMimeType>(),
37  std::make_unique<RTStructMimeType>()
38  };
39 }
40 
41 // Mime Types
42 
45 {
46  std::string category = "DICOMRT";
47  this->SetCategory(category);
48  this->SetComment("RTDose");
49 
50  this->AddExtension("dcm");
51 }
52 
53 bool DicomRTMimeTypes::RTDoseMimeType::AppliesTo(const std::string &path) const
54 {
55  bool canRead( CustomMimeType::AppliesTo(path) );
56 
57  if (!canRead) {
58  return false;
59  }
60 
61  if (!canReadByDicomFileReader(path)) {
62  return false;
63  }
64 
65  auto modality = GetModality(path);
66 
67  if (modality == "RTDOSE") {
68  return true;
69  }
70  else {
71  return false;
72  }
73 }
74 
75 std::string DicomRTMimeTypes::GetModality(const std::string & path)
76 {
78 
79  auto tagsOfInterest = toiSrv->GetTagsOfInterest();
80 
81  DICOMTagPathList tagsOfInterestList;
82  for (const auto& tag : tagsOfInterest) {
83  tagsOfInterestList.push_back(tag.first);
84  }
85 
86  mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New();
87  scanner->SetInputFiles({ path });
88  scanner->AddTagPaths(tagsOfInterestList);
89  scanner->Scan();
90 
91  mitk::DICOMDatasetAccessingImageFrameList frames = scanner->GetFrameInfoList();
92  std::string modality = "";
93  if (frames.empty())
94  return modality;
95  auto findings = frames.front()->GetTagValueAsString(DICOMTagPath(0x0008, 0x0060));
96 
97  modality = findings.front().value;
98  return modality;
99 }
100 
101 bool DicomRTMimeTypes::canReadByDicomFileReader(const std::string & filename)
102 {
103  mitk::DICOMFileReaderSelector::Pointer selector = mitk::DICOMFileReaderSelector::New();
104  selector->LoadBuiltIn3DConfigs();
105  selector->SetInputFiles({ filename });
106 
107  mitk::DICOMFileReader::Pointer reader = selector->GetFirstReaderWithMinimumNumberOfOutputImages();
108 
109  if (reader.IsNull()) {
110  return false;
111  }
112  else {
113  return true;
114  }
115 }
116 
118 {
119  return new RTDoseMimeType(*this);
120 }
121 
124 {
125  std::string category = "DICOMRT";
126  this->SetCategory(category);
127  this->SetComment("RTStruct");
128 
129  this->AddExtension("dcm");
130 }
131 
132 bool DicomRTMimeTypes::RTStructMimeType::AppliesTo(const std::string &path) const
133 {
134  bool canRead(CustomMimeType::AppliesTo(path));
135 
136  if (!canRead) {
137  return false;
138  }
139 
140  auto modality = GetModality(path);
141  if (modality == "RTSTRUCT") {
142  return true;
143  }
144  else {
145  return false;
146  }
147 }
148 
150 {
151  return new RTStructMimeType(*this);
152 }
153 
156 {
157  std::string category = "DICOMRT";
158  this->SetCategory(category);
159  this->SetComment("RTPLAN");
160 
161  this->AddExtension("dcm");
162 }
163 
164 bool DicomRTMimeTypes::RTPlanMimeType::AppliesTo(const std::string &path) const
165 {
166  bool canRead(CustomMimeType::AppliesTo(path));
167 
168  if (!canRead) {
169  return false;
170  }
171 
172  auto modality = GetModality(path);
173  if (modality == "RTPLAN") {
174  return true;
175  }
176  else {
177  return false;
178  }
179 }
180 
182 {
183  return new RTPlanMimeType(*this);
184 }
185 
186 
188 {
189  return RTDoseMimeType();
190 }
191 
193 {
194  return RTStructMimeType();
195 }
196 
198 {
199  return RTPlanMimeType();
200 }
201 
202 // Names
204 {
205  return IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.dose";
206 }
207 
209 {
210  return IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.struct";
211 }
212 
214 {
215  return IOMimeTypes::DEFAULT_BASE_NAME() + ".dicomrt.plan";
216 }
217 
218 // Descriptions
219 
221 {
222  return "RTDOSE reader";
223 }
224 
226 {
227  return "RTSTRUCT reader";
228 }
229 
231 {
232  return "RTPLAN reader";
233 }
234 
236 {
237  mitk::IDICOMTagsOfInterest* result = nullptr;
238 
239  std::vector<us::ServiceReference<mitk::IDICOMTagsOfInterest> > toiRegisters = us::GetModuleContext()->GetServiceReferences<mitk::IDICOMTagsOfInterest>();
240  if (!toiRegisters.empty())
241  {
242  if (toiRegisters.size() > 1)
243  {
244  MITK_WARN << "Multiple DICOM tags of interest services found. Using just one.";
245  }
246  result = us::GetModuleContext()->GetService<mitk::IDICOMTagsOfInterest>(toiRegisters.front());
247  }
248 
249  return result;
250 }
251 
252 }
Class is used to identify (nested) attributes in a DICOM dataset. In contrast to the class DICOMTag...
RTStructMimeType * Clone() const override
DataCollection - Class to facilitate loading/accessing structured data.
static std::string DICOMRT_DOSE_MIMETYPE_NAME()
virtual bool AppliesTo(const std::string &path) const
Checks if the MimeType can handle file at the given location.
void SetComment(const std::string &comment)
static RTStructMimeType DICOMRT_STRUCT_MIMETYPE()
Interface of DICOM tags of interest service.
static mitk::IDICOMTagsOfInterest * GetDicomTagsOfInterestService()
void * GetService(const ServiceReferenceBase &reference)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
static RTPlanMimeType DICOMRT_PLAN_MIMETYPE()
static std::array< std::unique_ptr< CustomMimeType >, 3 > Get()
RTDoseMimeType * Clone() const override
static std::string DEFAULT_BASE_NAME()
#define MITK_WARN
Definition: mitkLogMacros.h:19
static std::string DICOMRT_PLAN_MIMETYPE_DESCRIPTION()
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
static RTDoseMimeType DICOMRT_DOSE_MIMETYPE()
static std::string DICOMRT_DOSE_MIMETYPE_DESCRIPTION()
static std::string DICOMRT_STRUCT_MIMETYPE_DESCRIPTION()
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::string DICOMRT_PLAN_MIMETYPE_NAME()
void SetCategory(const std::string &category)
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
static std::string GetModality(const std::string &path)
static std::string DICOMRT_STRUCT_MIMETYPE_NAME()
std::vector< DICOMDatasetAccessingImageFrameInfo::Pointer > DICOMDatasetAccessingImageFrameList
virtual DICOMTagPathMapType GetTagsOfInterest() const =0
static bool canReadByDicomFileReader(const std::string &path)
RTPlanMimeType * Clone() const override
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.