Medical Imaging Interaction Toolkit  2018.4.99-9a29ffc6
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::BaseDicomMimeType::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_DEBUG << "DICOM Modality detected by MimeType "<< this->GetName() << " 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 
91  {
92  }
93 
95 
96  std::vector<CustomMimeType *> IOMimeTypes::Get()
97  {
98  std::vector<CustomMimeType *> mimeTypes;
99 
100  // order matters here (descending rank for mime types)
101 
102  mimeTypes.push_back(NRRD_MIMETYPE().Clone());
103  mimeTypes.push_back(NIFTI_MIMETYPE().Clone());
104 
105  mimeTypes.push_back(VTK_IMAGE_MIMETYPE().Clone());
106  mimeTypes.push_back(VTK_PARALLEL_IMAGE_MIMETYPE().Clone());
107  mimeTypes.push_back(VTK_IMAGE_LEGACY_MIMETYPE().Clone());
108 
109  mimeTypes.push_back(DICOM_MIMETYPE().Clone());
110 
111  mimeTypes.push_back(VTK_POLYDATA_MIMETYPE().Clone());
112  mimeTypes.push_back(VTK_PARALLEL_POLYDATA_MIMETYPE().Clone());
113  mimeTypes.push_back(VTK_POLYDATA_LEGACY_MIMETYPE().Clone());
114 
115  mimeTypes.push_back(STEREOLITHOGRAPHY_MIMETYPE().Clone());
116  mimeTypes.push_back(WAVEFRONT_OBJ_MIMETYPE().Clone());
117  mimeTypes.push_back(STANFORD_PLY_MIMETYPE().Clone());
118 
119  mimeTypes.push_back(RAW_MIMETYPE().Clone());
120  mimeTypes.push_back(POINTSET_MIMETYPE().Clone());
121  return mimeTypes;
122  }
123 
125  {
126  CustomMimeType mimeType(VTK_IMAGE_NAME());
127  mimeType.AddExtension("vti");
128  mimeType.SetCategory(CATEGORY_IMAGES());
129  mimeType.SetComment("VTK Image");
130  return mimeType;
131  }
132 
134  {
136  mimeType.AddExtension("vtk");
137  mimeType.SetCategory(CATEGORY_IMAGES());
138  mimeType.SetComment("VTK Legacy Image");
139  return mimeType;
140  }
141 
143  {
145  mimeType.AddExtension("pvti");
146  mimeType.SetCategory(CATEGORY_IMAGES());
147  mimeType.SetComment("VTK Parallel Image");
148  return mimeType;
149  }
150 
152  {
153  CustomMimeType mimeType(VTK_POLYDATA_NAME());
154  mimeType.AddExtension("vtp");
155  mimeType.SetCategory(CATEGORY_SURFACES());
156  mimeType.SetComment("VTK PolyData");
157  return mimeType;
158  }
159 
161  {
163  mimeType.AddExtension("vtk");
164  mimeType.SetCategory(CATEGORY_SURFACES());
165  mimeType.SetComment("VTK Legacy PolyData");
166  return mimeType;
167  }
168 
170  {
172  mimeType.AddExtension("pvtp");
173  mimeType.SetCategory(CATEGORY_SURFACES());
174  mimeType.SetComment("VTK Parallel PolyData");
175  return mimeType;
176  }
177 
179  {
181  mimeType.AddExtension("stl");
182  mimeType.SetCategory(CATEGORY_SURFACES());
183  mimeType.SetComment("Stereolithography");
184  return mimeType;
185  }
186 
188  {
190  mimeType.AddExtension("obj");
191  mimeType.SetCategory(CATEGORY_SURFACES());
192  mimeType.SetComment("Wavefront OBJ");
193  return mimeType;
194  }
195 
197  {
198  CustomMimeType mimeType(STANFORD_PLY_NAME());
199  mimeType.AddExtension("ply");
200  mimeType.SetCategory(CATEGORY_SURFACES());
201  mimeType.SetComment("Stanford PLY");
202  return mimeType;
203  }
204 
206  {
207  static std::string name = DEFAULT_BASE_NAME() + ".stl";
208  return name;
209  }
210 
212  {
213  static std::string name = DEFAULT_BASE_NAME() + ".obj";
214  return name;
215  }
216 
218  {
219  static std::string name = DEFAULT_BASE_NAME() + ".ply";
220  return name;
221  }
222 
224  {
225  static std::string name = "application/vnd.mitk";
226  return name;
227  }
228 
230  {
231  static std::string cat = "Images";
232  return cat;
233  }
234 
236  {
237  static std::string cat = "Surfaces";
238  return cat;
239  }
240 
242  {
243  static std::string name = DEFAULT_BASE_NAME() + ".vtk.image";
244  return name;
245  }
246 
248  {
249  static std::string name = DEFAULT_BASE_NAME() + ".vtk.image.legacy";
250  return name;
251  }
252 
254  {
255  static std::string name = DEFAULT_BASE_NAME() + ".vtk.parallel.image";
256  return name;
257  }
258 
260  {
261  static std::string name = DEFAULT_BASE_NAME() + ".vtk.polydata";
262  return name;
263  }
264 
266  {
267  static std::string name = DEFAULT_BASE_NAME() + ".vtk.polydata.legacy";
268  return name;
269  }
270 
272  {
273  static std::string name = DEFAULT_BASE_NAME() + ".vtk.parallel.polydata";
274  return name;
275  }
276 
278  {
280  mimeType.AddExtension("nrrd");
281  mimeType.AddExtension("nhdr");
282  mimeType.SetCategory("Images");
283  mimeType.SetComment("NRRD");
284  return mimeType;
285  }
286 
288  {
290  mimeType.AddExtension("nii");
291  mimeType.AddExtension("nii.gz");
292  mimeType.AddExtension("hdr");
293  mimeType.AddExtension("hdr.gz");
294  mimeType.AddExtension("img");
295  mimeType.AddExtension("img.gz");
296  mimeType.AddExtension("nia");
297  mimeType.SetCategory("Images");
298  mimeType.SetComment("Nifti");
299  return mimeType;
300  }
301 
303  {
304  CustomMimeType mimeType(RAW_MIMETYPE_NAME());
305  mimeType.AddExtension("raw");
306  mimeType.SetCategory("Images");
307  mimeType.SetComment("Raw data");
308  return mimeType;
309  }
310 
313  {
314  static std::string name = DEFAULT_BASE_NAME() + ".image.nrrd";
315  return name;
316  }
317 
319  {
320  static std::string name = DEFAULT_BASE_NAME() + ".image.nifti";
321  return name;
322  }
323 
325  {
326  static std::string name = DEFAULT_BASE_NAME() + ".image.raw";
327  return name;
328  }
329 
331  {
332  static std::string name = DEFAULT_BASE_NAME() + ".image.dicom";
333  return name;
334  }
335 
337  {
339  mimeType.AddExtension("mps");
340  mimeType.SetCategory("Point Sets");
341  mimeType.SetComment("MITK Point Set");
342  return mimeType;
343  }
344 
346  {
347  static std::string name = DEFAULT_BASE_NAME() + ".pointset";
348  return name;
349  }
350 
352  {
353  mitk::CustomMimeType mimeType(DEFAULT_BASE_NAME() + ".geometrydata");
354  mimeType.AddExtension("mitkgeometry");
355  mimeType.SetCategory("Geometries");
356  mimeType.SetComment("GeometryData object");
357  return mimeType;
358  }
359 }
static std::vector< CustomMimeType * > Get()
static std::string WAVEFRONT_OBJ_NAME()
static CustomMimeType NRRD_MIMETYPE()
static std::string VTK_PARALLEL_POLYDATA_NAME()
static CustomMimeType VTK_POLYDATA_LEGACY_MIMETYPE()
std::string GetName() const
Returns the unique name for the MimeType.
static CustomMimeType VTK_IMAGE_LEGACY_MIMETYPE()
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
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...
BaseDicomMimeType * Clone() const override
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)
BaseDicomMimeType(const std::string &name)
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()