Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 #if !defined(MITK_WINDOWS_NO_UNDEF) && defined(GetTempPath)
30  #undef GetTempPath
31 #endif
32 
33 namespace us
34 {
35  class ModuleResource;
36 }
37 
38 namespace mitk
39 {
40  class PropertyList;
41 
50  {
51  public:
57  {
58  LoadInfo(const std::string &path);
59 
60  std::string m_Path;
61  std::vector<BaseData::Pointer> m_Output;
62 
64  bool m_Cancel;
65 
67  };
68 
74  {
75  virtual bool operator()(LoadInfo &loadInfo) const = 0;
76  };
77 
79  {
80  SaveInfo(const BaseData *baseData, const MimeType &mimeType, const std::string &path);
81 
82  bool operator<(const SaveInfo &other) const;
83 
86 
92  std::string m_Path;
94  bool m_Cancel;
95  };
96 
102  {
103  virtual bool operator()(SaveInfo &saveInfo) const = 0;
104  };
105 
111  static std::string GetProgramPath();
112 
118  static std::string GetTempPath();
119 
125  static char GetDirectorySeparator();
126 
147  static std::string CreateTemporaryFile(std::ofstream &tmpStream,
148  const std::string &templateName = "XXXXXX",
149  std::string path = std::string());
150 
173  static std::string CreateTemporaryFile(std::ofstream &tmpStream,
174  std::ios_base::openmode mode,
175  const std::string &templateName = "XXXXXX",
176  std::string path = std::string());
177 
198  static std::string CreateTemporaryFile(const std::string &templateName = "XXXXXX",
199  std::string path = std::string());
200 
217  static std::string CreateTemporaryDirectory(const std::string &templateName = "XXXXXX",
218  std::string path = std::string());
219 
236  static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage,
237  const ReaderOptionsFunctorBase *optionsCallback = nullptr);
238 
254  static DataStorage::SetOfObjects::Pointer Load(const std::string &path,
255  const IFileReader::Options &options,
256  DataStorage &storage);
257 
273  static std::vector<BaseData::Pointer> Load(const std::string &path,
274  const ReaderOptionsFunctorBase *optionsCallback = nullptr);
275 
276  template <typename T>
277  static typename T::Pointer Load(const std::string& path, const ReaderOptionsFunctorBase *optionsCallback = nullptr)
278  {
279  return dynamic_cast<T*>(Load(path, optionsCallback).at(0).GetPointer());
280  }
281 
296  static std::vector<BaseData::Pointer> Load(const std::string &path, const IFileReader::Options &options);
297 
298  template <typename T>
299  static typename T::Pointer Load(const std::string& path, const IFileReader::Options &options)
300  {
301  return dynamic_cast<T*>(Load(path, options).at(0).GetPointer());
302  }
303 
318  static DataStorage::SetOfObjects::Pointer Load(const std::vector<std::string> &paths, DataStorage &storage,
319  const ReaderOptionsFunctorBase *optionsCallback = nullptr);
320 
321  static std::vector<BaseData::Pointer> Load(const std::vector<std::string> &paths,
322  const ReaderOptionsFunctorBase *optionsCallback = nullptr);
323 
333  static std::vector<BaseData::Pointer> Load(const us::ModuleResource &usResource,
334  std::ios_base::openmode mode = std::ios_base::in);
335 
336  template <typename T>
337  static typename T::Pointer Load(const us::ModuleResource &usResource, std::ios_base::openmode mode = std::ios_base::in)
338  {
339  return dynamic_cast<T*>(Load(usResource, mode).at(0).GetPointer());
340  }
341 
342  static BaseData::Pointer Load(const std::string& path, const PropertyList* properties);
343 
354  static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty = false);
355 
367  static void Save(const mitk::BaseData *data, const std::string &path, const IFileWriter::Options &options, bool setPathProperty = false);
368 
382  static void Save(const mitk::BaseData *data,
383  const std::string &mimeType,
384  const std::string &path,
385  bool addExtension = true,
386  bool setPathProperty = false);
387 
402  static void Save(const mitk::BaseData *data,
403  const std::string &mimeType,
404  const std::string &path,
405  const mitk::IFileWriter::Options &options,
406  bool addExtension = true,
407  bool setPathProperty = false);
408 
420  static void Save(std::vector<SaveInfo> &saveInfos, bool setPathProperty = false);
421 
422  protected:
423  static std::string Load(std::vector<LoadInfo> &loadInfos,
424  DataStorage::SetOfObjects *nodeResult,
425  DataStorage *ds,
426  const ReaderOptionsFunctorBase *optionsCallback);
427 
428  static std::string Save(const BaseData *data,
429  const std::string &mimeType,
430  const std::string &path,
431  WriterOptionsFunctorBase *optionsCallback,
432  bool addExtension,
433  bool setPathProperty);
434 
435  static std::string Save(std::vector<SaveInfo> &saveInfos,
436  WriterOptionsFunctorBase *optionsCallback,
437  bool setPathProperty);
438 
439  private:
440  struct Impl;
441  };
442 }
443 
444 #endif
mitk::IOUtil::LoadInfo::m_Path
std::string m_Path
Definition: mitkIOUtil.h:60
mitk::IOUtil::ReaderOptionsFunctorBase
Definition: mitkIOUtil.h:73
mitkFileReaderSelector.h
mitk::DataStorage::SetOfObjects
itk::VectorContainer< unsigned int, DataNode::Pointer > SetOfObjects
A Container of objects that is used as a result set of GetSubset() query operations (Set of.
Definition: mitkDataStorage.h:46
mitkImage.h
mitk::IFileIO::Options
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:69
mitk::IOUtil::SaveInfo::m_MimeType
MimeType m_MimeType
The selected mime-type, used to restrict results from FileWriterSelector.
Definition: mitkIOUtil.h:90
mitkDataStorage.h
us
Definition: mitkAbstractFileReader.h:29
mitk::modelFit::operator<
bool operator<(const StaticParameterMap::ValueType &a, const StaticParameterMap::ValueType &b)
Compares two var lists and returns true if the first list's first item is lower than the second one's...
Definition: mitkModelFitStaticParameterMap.h:139
itk::SmartPointer< Self >
mitk::IOUtil::SaveInfo::m_Cancel
bool m_Cancel
Flag indicating if sub-sequent save operations are to be canceled.
Definition: mitkIOUtil.h:94
mitk::IOUtil::SaveInfo::m_Path
std::string m_Path
The path to write the BaseData object to.
Definition: mitkIOUtil.h:92
mitkPointSet.h
mitk::FileWriterSelector
Definition: mitkFileWriterSelector.h:29
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::IOUtil::Load
static T::Pointer Load(const std::string &path, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Definition: mitkIOUtil.h:277
mitkSurface.h
mitk::IOUtil::SaveInfo
Definition: mitkIOUtil.h:78
mitkIFileWriter.h
mitk::FileReaderSelector
Definition: mitkFileReaderSelector.h:29
mitk::IOUtil::Load
static T::Pointer Load(const std::string &path, const IFileReader::Options &options)
Definition: mitkIOUtil.h:299
MitkCoreExports.h
mitk::IOUtil::SaveInfo::m_WriterSelector
FileWriterSelector m_WriterSelector
Contains a set of IFileWriter objects.
Definition: mitkIOUtil.h:88
mitkIFileReader.h
mitk::PropertyList
Key-value list holding instances of BaseProperty.
Definition: mitkPropertyList.h:56
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitk::IOUtil::LoadInfo::m_ReaderSelector
FileReaderSelector m_ReaderSelector
Definition: mitkIOUtil.h:63
mitk::DataStorage
Data management class that handles 'was created by' relations.
Definition: mitkDataStorage.h:43
us::ModuleResource
Definition: usModuleResource.h:55
mitk::IOUtil::LoadInfo
Definition: mitkIOUtil.h:56
mitk::IOUtil::Load
static T::Pointer Load(const us::ModuleResource &usResource, std::ios_base::openmode mode=std::ios_base::in)
Definition: mitkIOUtil.h:337
mitk::IOUtil::LoadInfo::m_Properties
const PropertyList * m_Properties
Definition: mitkIOUtil.h:66
mitk::IOUtil::LoadInfo::m_Output
std::vector< BaseData::Pointer > m_Output
Definition: mitkIOUtil.h:61
mitk::IOUtil::WriterOptionsFunctorBase
Definition: mitkIOUtil.h:101
mitk::IOUtil::SaveInfo::m_BaseData
const BaseData * m_BaseData
The BaseData object to save.
Definition: mitkIOUtil.h:85
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::IOUtil
A utility class to load and save data from/to the local file system.
Definition: mitkIOUtil.h:49
mitk::IOUtil::LoadInfo::m_Cancel
bool m_Cancel
Definition: mitkIOUtil.h:64
mitkFileWriterSelector.h
mitk::MimeType
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
Definition: mitkMimeType.h:36