Medical Imaging Interaction Toolkit  2018.4.99-064ad45c
Medical Imaging Interaction Toolkit
mitkIOUtil.h
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 #ifndef MITKIOUTIL_H
14 #define MITKIOUTIL_H
15 
16 #include <MitkCoreExports.h>
17 #include <mitkDataStorage.h>
18 #include <mitkImage.h>
19 #include <mitkPointSet.h>
20 #include <mitkSurface.h>
21 
22 #include <mitkFileReaderSelector.h>
23 #include <mitkFileWriterSelector.h>
24 #include <mitkIFileReader.h>
25 #include <mitkIFileWriter.h>
26 
27 #include <fstream>
28 
29 namespace us
30 {
31  class ModuleResource;
32 }
33 
34 namespace mitk
35 {
44  {
45  public:
51  {
52  LoadInfo(const std::string &path);
53 
54  std::string m_Path;
55  std::vector<BaseData::Pointer> m_Output;
56 
58  bool m_Cancel;
59  };
60 
66  {
67  virtual bool operator()(LoadInfo &loadInfo) const = 0;
68  };
69 
71  {
72  SaveInfo(const BaseData *baseData, const MimeType &mimeType, const std::string &path);
73 
74  bool operator<(const SaveInfo &other) const;
75 
78 
84  std::string m_Path;
86  bool m_Cancel;
87  };
88 
94  {
95  virtual bool operator()(SaveInfo &saveInfo) const = 0;
96  };
97 
103  static std::string GetProgramPath();
104 
110  static std::string GetTempPath();
111 
117  static char GetDirectorySeparator();
118 
139  static std::string CreateTemporaryFile(std::ofstream &tmpStream,
140  const std::string &templateName = "XXXXXX",
141  std::string path = std::string());
142 
165  static std::string CreateTemporaryFile(std::ofstream &tmpStream,
166  std::ios_base::openmode mode,
167  const std::string &templateName = "XXXXXX",
168  std::string path = std::string());
169 
190  static std::string CreateTemporaryFile(const std::string &templateName = "XXXXXX",
191  std::string path = std::string());
192 
209  static std::string CreateTemporaryDirectory(const std::string &templateName = "XXXXXX",
210  std::string path = std::string());
211 
228  static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage,
229  const ReaderOptionsFunctorBase *optionsCallback = nullptr);
230 
246  static DataStorage::SetOfObjects::Pointer Load(const std::string &path,
247  const IFileReader::Options &options,
248  DataStorage &storage);
249 
265  static std::vector<BaseData::Pointer> Load(const std::string &path,
266  const ReaderOptionsFunctorBase *optionsCallback = nullptr);
267 
268  template <typename T>
269  static typename T::Pointer Load(const std::string& path, const ReaderOptionsFunctorBase *optionsCallback = nullptr)
270  {
271  return dynamic_cast<T*>(Load(path, optionsCallback).at(0).GetPointer());
272  }
273 
288  static std::vector<BaseData::Pointer> Load(const std::string &path, const IFileReader::Options &options);
289 
290  template <typename T>
291  static typename T::Pointer Load(const std::string& path, const IFileReader::Options &options)
292  {
293  return dynamic_cast<T*>(Load(path, options).at(0).GetPointer());
294  }
295 
310  static DataStorage::SetOfObjects::Pointer Load(const std::vector<std::string> &paths, DataStorage &storage,
311  const ReaderOptionsFunctorBase *optionsCallback = nullptr);
312 
313  static std::vector<BaseData::Pointer> Load(const std::vector<std::string> &paths,
314  const ReaderOptionsFunctorBase *optionsCallback = nullptr);
315 
325  static std::vector<BaseData::Pointer> Load(const us::ModuleResource &usResource,
326  std::ios_base::openmode mode = std::ios_base::in);
327 
328  template <typename T>
329  static typename T::Pointer Load(const us::ModuleResource &usResource, std::ios_base::openmode mode = std::ios_base::in)
330  {
331  return dynamic_cast<T*>(Load(usResource, mode).at(0).GetPointer());
332  }
333 
343  static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty = false);
344 
355  static void Save(const mitk::BaseData *data, const std::string &path, const IFileWriter::Options &options, bool setPathProperty = false);
356 
369  static void Save(const mitk::BaseData *data,
370  const std::string &mimeType,
371  const std::string &path,
372  bool addExtension = true,
373  bool setPathProperty = false);
374 
388  static void Save(const mitk::BaseData *data,
389  const std::string &mimeType,
390  const std::string &path,
391  const mitk::IFileWriter::Options &options,
392  bool addExtension = true,
393  bool setPathProperty = false);
394 
405  static void Save(std::vector<SaveInfo> &saveInfos, bool setPathProperty = false);
406 
407  protected:
408  static std::string Load(std::vector<LoadInfo> &loadInfos,
409  DataStorage::SetOfObjects *nodeResult,
410  DataStorage *ds,
411  const ReaderOptionsFunctorBase *optionsCallback);
412 
413  static std::string Save(const BaseData *data,
414  const std::string &mimeType,
415  const std::string &path,
416  WriterOptionsFunctorBase *optionsCallback,
417  bool addExtension,
418  bool setPathProperty);
419 
420  static std::string Save(std::vector<SaveInfo> &saveInfos,
421  WriterOptionsFunctorBase *optionsCallback,
422  bool setPathProperty);
423 
424  private:
425  struct Impl;
426  };
427 }
428 
429 #endif // MITKIOUTIL_H
Data management class that handles &#39;was created by&#39; relations.
#define MITKCORE_EXPORT
FileWriterSelector m_WriterSelector
Contains a set of IFileWriter objects.
Definition: mitkIOUtil.h:80
Base of all data objects.
Definition: mitkBaseData.h:42
static T::Pointer Load(const us::ModuleResource &usResource, std::ios_base::openmode mode=std::ios_base::in)
Definition: mitkIOUtil.h:329
bool operator<(const StaticParameterMap::ValueType &a, const StaticParameterMap::ValueType &b)
Compares two var lists and returns true if the first list&#39;s first item is lower than the second one&#39;s...
DataCollection - Class to facilitate loading/accessing structured data.
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:69
const BaseData * m_BaseData
The BaseData object to save.
Definition: mitkIOUtil.h:77
std::vector< BaseData::Pointer > m_Output
Definition: mitkIOUtil.h:55
MimeType m_MimeType
The selected mime-type, used to restrict results from FileWriterSelector.
Definition: mitkIOUtil.h:82
A utility class to load and save data from/to the local file system.
Definition: mitkIOUtil.h:43
std::string m_Path
Definition: mitkIOUtil.h:54
itk::VectorContainer< unsigned int, DataNode::Pointer > SetOfObjects
A Container of objects that is used as a result set of GetSubset() query operations (Set of...
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
Definition: mitkMimeType.h:36
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
bool m_Cancel
Flag indicating if sub-sequent save operations are to be canceled.
Definition: mitkIOUtil.h:86
FileReaderSelector m_ReaderSelector
Definition: mitkIOUtil.h:57
std::string m_Path
The path to write the BaseData object to.
Definition: mitkIOUtil.h:84
static T::Pointer Load(const std::string &path, const IFileReader::Options &options)
Definition: mitkIOUtil.h:291
static T::Pointer Load(const std::string &path, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Definition: mitkIOUtil.h:269