Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkCESTIOMimeTypes.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 "mitkCESTIOMimeTypes.h"
14 #include "mitkIOMimeTypes.h"
15 #include <mitkCustomTagParser.h>
18 
19 #include <mitkLogMacros.h>
20 
21 #include <itkGDCMImageIO.h>
22 
23 #include <itksys/SystemTools.hxx>
24 
25 namespace mitk
26 {
27  std::vector<CustomMimeType *> MitkCESTIOMimeTypes::Get()
28  {
29  std::vector<CustomMimeType *> mimeTypes;
30 
31  // order matters here (descending rank for mime types)
32 
33  mimeTypes.push_back(CEST_DICOM_MIMETYPE().Clone());
34 
35  return mimeTypes;
36  }
37 
38  // Mime Types
39 
41  {
42  this->AddExtension("gdcm");
43  this->AddExtension("dcm");
44  this->AddExtension("DCM");
45  this->AddExtension("dc3");
46  this->AddExtension("DC3");
47  this->AddExtension("ima");
48  this->AddExtension("img");
49 
51  this->SetComment("CEST DICOM");
52  }
53 
54  bool MitkCESTIOMimeTypes::MitkCESTDicomMimeType::AppliesTo(const std::string &path) const
55  {
56  bool canRead(CustomMimeType::AppliesTo(path));
57 
58  // fix for bug 18572
59  // Currently this function is called for writing as well as reading, in that case
60  // the image information can of course not be read
61  // This is a bug, this function should only be called for reading.
62  if (!itksys::SystemTools::FileExists(path.c_str()))
63  {
64  return canRead;
65  }
66  // end fix for bug 18572
67 
68  // Ask the GDCM ImageIO class directly
69  itk::GDCMImageIO::Pointer gdcmIO = itk::GDCMImageIO::New();
70  canRead = gdcmIO->CanReadFile(path.c_str());
71 
72  if (!canRead)
73  {
74  return canRead;
75  }
76 
77  mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New();
78 
79  mitk::DICOMTag siemensCESTprivateTag(0x0029, 0x1020);
80 
81  mitk::StringList relevantFiles;
82  relevantFiles.push_back(path);
83 
84  scanner->AddTag(siemensCESTprivateTag);
85  scanner->SetInputFiles(relevantFiles);
86  scanner->Scan();
87  mitk::DICOMTagCache::Pointer tagCache = scanner->GetScanCache();
88 
89  mitk::DICOMImageFrameList imageFrameList = mitk::ConvertToDICOMImageFrameList(tagCache->GetFrameInfoList());
90  mitk::DICOMImageFrameInfo *firstFrame = imageFrameList.begin()->GetPointer();
91 
92  std::string byteString = tagCache->GetTagValue(firstFrame, siemensCESTprivateTag).value;
93 
94  if (byteString.empty()) {
95  return false;
96  }
97  mitk::CustomTagParser tagParser(relevantFiles[0]);
98 
99  auto parsedPropertyList = tagParser.ParseDicomPropertyString(byteString);
100 
101  bool mapNotEmpty = parsedPropertyList->GetMap()->size() > 0;
102 
103  return mapNotEmpty;
104  }
105 
107  {
108  return new MitkCESTDicomMimeType(*this);
109  }
110 
112  {
113  return MitkCESTDicomMimeType();
114  }
115 
116  // Names
118  {
119  // create a unique and sensible name for this mime type
120  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".image.dicom.cest";
121  return name;
122  }
123 }
static MitkCESTDicomMimeType CEST_DICOM_MIMETYPE()
Representation of a DICOM tag.
Definition: mitkDICOMTag.h:32
DataCollection - Class to facilitate loading/accessing structured data.
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
virtual bool AppliesTo(const std::string &path) const
Checks if the MimeType can handle file at the given location.
mitk::PropertyList::Pointer ParseDicomPropertyString(std::string dicomPropertyString)
parse the provided string and return a property list based on the closest revision parameter mapping ...
void SetComment(const std::string &comment)
Describes a frame within a DICOM file.
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static std::string CATEGORY_IMAGES()
static std::string DEFAULT_BASE_NAME()
static std::string CEST_DICOM_MIMETYPE_NAME()
std::vector< DICOMImageFrameInfo::Pointer > DICOMImageFrameList
void AddExtension(const std::string &extension)
std::vector< std::string > StringList
MITKDICOMREADER_EXPORT mitk::DICOMImageFrameList ConvertToDICOMImageFrameList(const DICOMDatasetAccessingImageFrameList &input)
void SetCategory(const std::string &category)
static std::vector< CustomMimeType * > Get()
static mitk::PlanarFigure::Pointer Clone(mitk::PlanarFigure::Pointer original)
MitkCESTDicomMimeType * Clone() const override