Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkRTPlanReader.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 
14 #include "mitkRTPlanReader.h"
15 
17 #include "mitkIOMimeTypes.h"
18 #include "mitkDICOMTagPath.h"
21 
22 namespace mitk
23 {
24 
25  RTPlanReader::RTPlanReader() : AbstractFileReader(IOMimeTypes::DICOM_MIMETYPE_NAME(), "DICOM RTPlan File Reader") {
26  m_FileReaderServiceReg = RegisterService();
27  m_DICOMTagsOfInterestService = GetDicomTagsOfInterestService();
28  }
29 
30  RTPlanReader::RTPlanReader(const RTPlanReader& other) : mitk::AbstractFileReader(other)
31  {}
32 
33  RTPlanReader::~RTPlanReader(){}
34 
35  std::vector<itk::SmartPointer<BaseData> > RTPlanReader::Read()
36  {
37  std::vector<itk::SmartPointer<mitk::BaseData> > result;
38 
39  auto tagsOfInterest = m_DICOMTagsOfInterestService->GetTagsOfInterest();
40  DICOMTagPathList tagsOfInterestList;
41  for (const auto& tag : tagsOfInterest){
42  tagsOfInterestList.push_back(tag.first);
43  }
44 
45  std::string location = GetInputLocation();
46  mitk::StringList files = { location };
47  mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New();
48  scanner->SetInputFiles(files);
49  scanner->AddTagPaths(tagsOfInterestList);
50  scanner->Scan();
51 
52  mitk::DICOMDatasetAccessingImageFrameList frames = scanner->GetFrameInfoList();
53  if (frames.empty()){
54  MITK_ERROR << "Error reading the RTPLAN file" << std::endl;
55  return result;
56  }
57 
58  auto findings = ExtractPathsOfInterest(tagsOfInterestList, frames);
59 
60  //just create empty image. No image information available in RTPLAN. But properties will be attached.
61  Image::Pointer dummyImage = Image::New();
62  SetProperties(dummyImage, findings);
63 
64  result.push_back(dummyImage.GetPointer());
65 
66  return result;
67  }
68 
69  RTPlanReader* RTPlanReader::Clone() const
70  {
71  return new RTPlanReader(*this);
72  }
73 
75  {
76  std::vector<mitk::DICOMDatasetAccess::FindingsListType > findings;
77  for (const auto& entry : pathsOfInterest){
78  findings.push_back(frames.front()->GetTagValueAsString(entry));
79  }
80  return findings;
81  }
82 
84  {
85  for (const auto& finding : findings){
86  for (const auto& entry : finding){
87  const std::string propertyName = mitk::DICOMTagPathToPropertyName(entry.path);
89  property->SetValue(entry.value);
90  image->SetProperty(propertyName.c_str(), property);
91  }
92  }
93  }
94 
96  {
97  mitk::IDICOMTagsOfInterest* result = nullptr;
98 
99  std::vector<us::ServiceReference<mitk::IDICOMTagsOfInterest> > toiRegisters = us::GetModuleContext()->GetServiceReferences<mitk::IDICOMTagsOfInterest>();
100  if (!toiRegisters.empty())
101  {
102  if (toiRegisters.size() > 1)
103  {
104  MITK_WARN << "Multiple DICOM tags of interest services found. Using just one.";
105  }
106  result = us::GetModuleContext()->GetService<mitk::IDICOMTagsOfInterest>(toiRegisters.front());
107  }
108 
109  return result;
110  }
111 
112 }
MITKDICOMREADER_EXPORT FindingsListVectorType ExtractPathsOfInterest(const DICOMTagPathList &pathsOfInterest, const DICOMDatasetAccessingImageFrameList &frames)
std::vector< mitk::DICOMDatasetAccess::FindingsListType > FindingsListVectorType
#define MITK_ERROR
Definition: mitkLogMacros.h:20
itk::SmartPointer< Self > Pointer
Definition: mitkImage.h:84
DataCollection - Class to facilitate loading/accessing structured data.
Interface of DICOM tags of interest service.
void * GetService(const ServiceReferenceBase &reference)
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyName(const DICOMTagPath &tagPath)
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
#define MITK_WARN
Definition: mitkLogMacros.h:19
mitk::Image::Pointer image
static Pointer New()
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
std::vector< std::string > StringList
std::vector< DICOMTagPath > DICOMTagPathList
MITKDICOMREADER_EXPORT void SetProperties(BaseDataPointer image, const FindingsListVectorType &findings)
std::vector< DICOMDatasetAccessingImageFrameInfo::Pointer > DICOMDatasetAccessingImageFrameList
MITKDICOMREADER_EXPORT mitk::IDICOMTagsOfInterest * GetDicomTagsOfInterestService()
std::string GetInputLocation() const override
Get the current input location.
static mitk::PlanarFigure::Pointer Clone(mitk::PlanarFigure::Pointer original)
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.