Medical Imaging Interaction Toolkit  2018.4.99-b20efe7f
Medical Imaging Interaction Toolkit
mitkDICOMPMIOMimeTypes.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 "mitkDICOMPMIOMimeTypes.h"
14 #include "mitkIOMimeTypes.h"
15 
16 #include <mitkLogMacros.h>
17 
18 #include <itkGDCMImageIO.h>
19 #include <itksys/SystemTools.hxx>
20 
21 #include <dcmtk/dcmdata/dcfilefo.h>
22 #include <dcmtk/dcmdata/dcdeftag.h>
23 
24 namespace mitk
25 {
26  std::vector<CustomMimeType *> MitkDICOMPMIOMimeTypes::Get()
27  {
28  std::vector<CustomMimeType *> mimeTypes;
29 
30  // order matters here (descending rank for mime types)
31 
32  mimeTypes.push_back(DICOMPM_MIMETYPE().Clone());
33  return mimeTypes;
34  }
35 
37  {
38  this->AddExtension("dcm");
40  this->SetComment("DICOM PM");
41  }
42 
43  bool MitkDICOMPMIOMimeTypes::MitkDICOMPMMimeType::AppliesTo(const std::string &path) const
44  {
45  std::ifstream myfile;
46  myfile.open(path, std::ios::binary);
47  // myfile.seekg (128);
48  char *buffer = new char[128];
49  myfile.read(buffer, 128);
50  myfile.read(buffer, 4);
51  if (std::string(buffer).compare("DICM") != 0)
52  {
53  delete[] buffer;
54  return false;
55  }
56  delete[] buffer;
57 
58  bool canRead(CustomMimeType::AppliesTo(path));
59 
60  // fix for bug 18572
61  // Currently this function is called for writing as well as reading, in that case
62  // the image information can of course not be read
63  // This is a bug, this function should only be called for reading.
64  if (!itksys::SystemTools::FileExists(path.c_str()))
65  {
66  return canRead;
67  }
68  // end fix for bug 18572
69  DcmFileFormat dcmFileFormat;
70  OFCondition status = dcmFileFormat.loadFile(path.c_str());
71 
72  if (status.bad())
73  {
74  canRead = false;
75  }
76 
77  if (!canRead)
78  {
79  return canRead;
80  }
81 
82  OFString modality;
83  if (dcmFileFormat.getDataset()->findAndGetOFString(DCM_Modality, modality).good())
84  {
85  if (modality.compare("RWV") == 0)
86  {
87  canRead = true;
88  }
89  else
90  {
91  canRead = false;
92  }
93  }
94 
95  return canRead;
96  }
97 
99  {
100  return new MitkDICOMPMMimeType(*this);
101  }
102 
104  {
105  return MitkDICOMPMMimeType();
106  }
107 
108  // Names
110  {
111  // create a unique and sensible name for this mime type
112  static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".image.dicom.pm";
113  return name;
114  }
115 
116 
117 }
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
DataCollection - Class to facilitate loading/accessing structured data.
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 std::vector< CustomMimeType * > Get()
static std::string DICOMPM_MIMETYPE_NAME()
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()
bool compare(std::pair< double, int > i, std::pair< double, int > j)
void AddExtension(const std::string &extension)
void SetCategory(const std::string &category)
static MitkDICOMPMMimeType DICOMPM_MIMETYPE()