Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkIOMimeTypes.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 "mitkIOMimeTypes.h"
14 
15 #include "mitkCustomMimeType.h"
16 #include "mitkLogMacros.h"
17 
18 #include "itkGDCMImageIO.h"
19 #include "itkMetaDataObject.h"
20 
21 #include <itksys/SystemTools.hxx>
22 #include <itksys/Directory.hxx>
23 
24 namespace mitk
25 {
27  {
28  this->AddExtension("gdcm");
29  this->AddExtension("dcm");
30  this->AddExtension("DCM");
31  this->AddExtension("dc3");
32  this->AddExtension("DC3");
33  this->AddExtension("ima");
34  this->AddExtension("img");
35 
37  this->SetComment("DICOM");
38  }
39 
40  bool IOMimeTypes::DicomMimeType::AppliesTo(const std::string &path) const
41  {
42  // check whether directory or file
43  // if directory try to find first file within it instead
44  bool pathIsDirectory = itksys::SystemTools::FileIsDirectory(path);
45 
46  std::string filepath = path;
47 
48  if (pathIsDirectory)
49  {
50  itksys::Directory input;
51  input.Load(path.c_str());
52 
53  std::vector<std::string> files;
54  for (unsigned long idx = 0; idx<input.GetNumberOfFiles(); idx++)
55  {
56  if (!itksys::SystemTools::FileIsDirectory(input.GetFile(idx)))
57  {
58  std::string fullpath = path + "/" + std::string(input.GetFile(idx));
59  files.push_back(fullpath.c_str());
60  }
61  }
62  filepath = files.front();
63  }
64 
65  // Ask the GDCM ImageIO class directly
66  itk::GDCMImageIO::Pointer gdcmIO = itk::GDCMImageIO::New();
67  gdcmIO->SetFileName(filepath);
68  try {
69  gdcmIO->ReadImageInformation();
70  }
71  catch (const itk::ExceptionObject & /*err*/) {
72  return false;
73  }
74 
75  //DICOMRT modalities have specific reader, don't read with normal DICOM readers
76  std::string modality;
77  itk::MetaDataDictionary& dict = gdcmIO->GetMetaDataDictionary();
78  itk::ExposeMetaData<std::string>(dict, "0008|0060", modality);
79  MITK_INFO << "DICOM Modality is " << modality;
80  if (modality == "RTSTRUCT" || modality == "RTDOSE" || modality == "RTPLAN") {
81  return false;
82  }
83  else {
84  return gdcmIO->CanReadFile(filepath.c_str());
85  }
86  }
87 
89  std::vector<CustomMimeType *> IOMimeTypes::Get()
90  {
91  std::vector<CustomMimeType *> mimeTypes;
92 
93  // order matters here (descending rank for mime types)
94 
95  mimeTypes.push_back(NRRD_MIMETYPE().Clone());
96  mimeTypes.push_back(NIFTI_MIMETYPE().Clone());
97 
98  mimeTypes.push_back(VTK_IMAGE_MIMETYPE().Clone());
99  mimeTypes.push_back(VTK_PARALLEL_IMAGE_MIMETYPE().Clone());
100  mimeTypes.push_back(VTK_IMAGE_LEGACY_MIMETYPE().Clone());
101 
102  mimeTypes.push_back(DICOM_MIMETYPE().Clone());
103 
104  mimeTypes.push_back(VTK_POLYDATA_MIMETYPE().Clone());
105  mimeTypes.push_back(VTK_PARALLEL_POLYDATA_MIMETYPE().Clone());
106  mimeTypes.push_back(VTK_POLYDATA_LEGACY_MIMETYPE().Clone());
107 
108  mimeTypes.push_back(STEREOLITHOGRAPHY_MIMETYPE().Clone());
109  mimeTypes.push_back(WAVEFRONT_OBJ_MIMETYPE().Clone());
110  mimeTypes.push_back(STANFORD_PLY_MIMETYPE().Clone());
111 
112  mimeTypes.push_back(RAW_MIMETYPE().Clone());
113  mimeTypes.push_back(POINTSET_MIMETYPE().Clone());
114  return mimeTypes;
115  }
116 
118  {
119  CustomMimeType mimeType(VTK_IMAGE_NAME());
120  mimeType.AddExtension("vti");
121  mimeType.SetCategory(CATEGORY_IMAGES());
122  mimeType.SetComment("VTK Image");
123  return mimeType;
124  }
125 
127  {
129  mimeType.AddExtension("vtk");
130  mimeType.SetCategory(CATEGORY_IMAGES());
131  mimeType.SetComment("VTK Legacy Image");
132  return mimeType;
133  }
134 
136  {
138  mimeType.AddExtension("pvti");
139  mimeType.SetCategory(CATEGORY_IMAGES());
140  mimeType.SetComment("VTK Parallel Image");
141  return mimeType;
142  }
143 
145  {
146  CustomMimeType mimeType(VTK_POLYDATA_NAME());
147  mimeType.AddExtension("vtp");
148  mimeType.SetCategory(CATEGORY_SURFACES());
149  mimeType.SetComment("VTK PolyData");
150  return mimeType;
151  }
152 
154  {
156  mimeType.AddExtension("vtk");
157  mimeType.SetCategory(CATEGORY_SURFACES());
158  mimeType.SetComment("VTK Legacy PolyData");
159  return mimeType;
160  }
161 
163  {
165  mimeType.AddExtension("pvtp");
166  mimeType.SetCategory(CATEGORY_SURFACES());
167  mimeType.SetComment("VTK Parallel PolyData");
168  return mimeType;
169  }
170 
172  {
174  mimeType.AddExtension("stl");
175  mimeType.SetCategory(CATEGORY_SURFACES());
176  mimeType.SetComment("Stereolithography");
177  return mimeType;
178  }
179 
181  {
183  mimeType.AddExtension("obj");
184  mimeType.SetCategory(CATEGORY_SURFACES());
185  mimeType.SetComment("Wavefront OBJ");
186  return mimeType;
187  }
188 
190  {
191  CustomMimeType mimeType(STANFORD_PLY_NAME());
192  mimeType.AddExtension("ply");
193  mimeType.SetCategory(CATEGORY_SURFACES());
194  mimeType.SetComment("Stanford PLY");
195  return mimeType;
196  }
197 
199  {
200  static std::string name = DEFAULT_BASE_NAME() + ".stl";
201  return name;
202  }
203 
205  {
206  static std::string name = DEFAULT_BASE_NAME() + ".obj";
207  return name;
208  }
209 
211  {
212  static std::string name = DEFAULT_BASE_NAME() + ".ply";
213  return name;
214  }
215 
217  {
218  static std::string name = "application/vnd.mitk";
219  return name;
220  }
221 
223  {
224  static std::string cat = "Images";
225  return cat;
226  }
227 
229  {
230  static std::string cat = "Surfaces";
231  return cat;
232  }
233 
235  {
236  static std::string name = DEFAULT_BASE_NAME() + ".vtk.image";
237  return name;
238  }
239 
241  {
242  static std::string name = DEFAULT_BASE_NAME() + ".vtk.image.legacy";
243  return name;
244  }
245 
247  {
248  static std::string name = DEFAULT_BASE_NAME() + ".vtk.parallel.image";
249  return name;
250  }
251 
253  {
254  static std::string name = DEFAULT_BASE_NAME() + ".vtk.polydata";
255  return name;
256  }
257 
259  {
260  static std::string name = DEFAULT_BASE_NAME() + ".vtk.polydata.legacy";
261  return name;
262  }
263 
265  {
266  static std::string name = DEFAULT_BASE_NAME() + ".vtk.parallel.polydata";
267  return name;
268  }
269 
271  {
273  mimeType.AddExtension("nrrd");
274  mimeType.AddExtension("nhdr");
275  mimeType.SetCategory("Images");
276  mimeType.SetComment("NRRD");
277  return mimeType;
278  }
279 
281  {
283  mimeType.AddExtension("nii");
284  mimeType.AddExtension("nii.gz");
285  mimeType.AddExtension("hdr");
286  mimeType.AddExtension("hdr.gz");
287  mimeType.AddExtension("img");
288  mimeType.AddExtension("img.gz");
289  mimeType.AddExtension("nia");
290  mimeType.SetCategory("Images");
291  mimeType.SetComment("Nifti");
292  return mimeType;
293  }
294 
296  {
297  CustomMimeType mimeType(RAW_MIMETYPE_NAME());
298  mimeType.AddExtension("raw");
299  mimeType.SetCategory("Images");
300  mimeType.SetComment("Raw data");
301  return mimeType;
302  }
303 
306  {
307  static std::string name = DEFAULT_BASE_NAME() + ".image.nrrd";
308  return name;
309  }
310 
312  {
313  static std::string name = DEFAULT_BASE_NAME() + ".image.nifti";
314  return name;
315  }
316 
318  {
319  static std::string name = DEFAULT_BASE_NAME() + ".image.raw";
320  return name;
321  }
322 
324  {
325  static std::string name = DEFAULT_BASE_NAME() + ".image.dicom";
326  return name;
327  }
328 
330  {
332  mimeType.AddExtension("mps");
333  mimeType.SetCategory("Point Sets");
334  mimeType.SetComment("MITK Point Set");
335  return mimeType;
336  }
337 
339  {
340  static std::string name = DEFAULT_BASE_NAME() + ".pointset";
341  return name;
342  }
343 
345  {
346  mitk::CustomMimeType mimeType(DEFAULT_BASE_NAME() + ".geometrydata");
347  mimeType.AddExtension("mitkgeometry");
348  mimeType.SetCategory("Geometries");
349  mimeType.SetComment("GeometryData object");
350  return mimeType;
351  }
352 }
static std::vector< CustomMimeType * > Get()
#define MITK_INFO
Definition: mitkLogMacros.h:18
static std::string WAVEFRONT_OBJ_NAME()
static CustomMimeType NRRD_MIMETYPE()
static std::string VTK_PARALLEL_POLYDATA_NAME()
static CustomMimeType VTK_POLYDATA_LEGACY_MIMETYPE()
static CustomMimeType VTK_IMAGE_LEGACY_MIMETYPE()
DataCollection - Class to facilitate loading/accessing structured data.
static std::string VTK_IMAGE_LEGACY_NAME()
static std::string VTK_POLYDATA_NAME()
bool AppliesTo(const std::string &path) const override
Checks if the MimeType can handle file at the given location.
static CustomMimeType VTK_PARALLEL_POLYDATA_MIMETYPE()
static std::string VTK_IMAGE_NAME()
static CustomMimeType VTK_IMAGE_MIMETYPE()
static std::string STEREOLITHOGRAPHY_NAME()
DicomMimeType * Clone() const override
void SetComment(const std::string &comment)
static CustomMimeType VTK_POLYDATA_MIMETYPE()
static CustomMimeType POINTSET_MIMETYPE()
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static std::string DICOM_MIMETYPE_NAME()
static std::string CATEGORY_IMAGES()
static std::string NIFTI_MIMETYPE_NAME()
static CustomMimeType STEREOLITHOGRAPHY_MIMETYPE()
static std::string DEFAULT_BASE_NAME()
static std::string RAW_MIMETYPE_NAME()
static CustomMimeType RAW_MIMETYPE()
static DicomMimeType DICOM_MIMETYPE()
static CustomMimeType WAVEFRONT_OBJ_MIMETYPE()
static CustomMimeType NIFTI_MIMETYPE()
static std::string VTK_PARALLEL_IMAGE_NAME()
void AddExtension(const std::string &extension)
void SetCategory(const std::string &category)
static std::string POINTSET_MIMETYPE_NAME()
static std::string VTK_POLYDATA_LEGACY_NAME()
static std::string STANFORD_PLY_NAME()
static CustomMimeType STANFORD_PLY_MIMETYPE()
static CustomMimeType VTK_PARALLEL_IMAGE_MIMETYPE()
static std::string NRRD_MIMETYPE_NAME()
static CustomMimeType GEOMETRY_DATA_MIMETYPE()
static std::string CATEGORY_SURFACES()