Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKIOUTIL_H
18 #define MITKIOUTIL_H
19 
20 #include <MitkCoreExports.h>
21 #include <mitkDataStorage.h>
22 #include <mitkImage.h>
23 #include <mitkPointSet.h>
24 #include <mitkSurface.h>
25 
26 #include <mitkFileReaderSelector.h>
27 #include <mitkFileWriterSelector.h>
28 #include <mitkIFileReader.h>
29 #include <mitkIFileWriter.h>
30 
31 #include <fstream>
32 
33 namespace us
34 {
35  class ModuleResource;
36 }
37 
38 namespace mitk
39 {
51  {
52  public:
54  {
55  LoadInfo(const std::string &path);
56 
57  std::string m_Path;
58  std::vector<BaseData::Pointer> m_Output;
59 
61  bool m_Cancel;
62  };
63 
65  {
66  SaveInfo(const BaseData *baseData, const MimeType &mimeType, const std::string &path);
67 
68  bool operator<(const SaveInfo &other) const;
69 
72 
78  std::string m_Path;
80  bool m_Cancel;
81  };
82 
88  static std::string GetProgramPath();
89 
95  static std::string GetTempPath();
96 
102  static char GetDirectorySeparator();
103 
124  static std::string CreateTemporaryFile(std::ofstream &tmpStream,
125  const std::string &templateName = "XXXXXX",
126  std::string path = std::string());
127 
150  static std::string CreateTemporaryFile(std::ofstream &tmpStream,
151  std::ios_base::openmode mode,
152  const std::string &templateName = "XXXXXX",
153  std::string path = std::string());
154 
175  static std::string CreateTemporaryFile(const std::string &templateName = "XXXXXX",
176  std::string path = std::string());
177 
194  static std::string CreateTemporaryDirectory(const std::string &templateName = "XXXXXX",
195  std::string path = std::string());
196 
210  static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage);
211 
212  static DataStorage::SetOfObjects::Pointer Load(const std::string &path,
213  const IFileReader::Options &options,
214  DataStorage &storage);
215 
216  static std::vector<BaseData::Pointer> Load(const std::string &path);
217 
218  static std::vector<BaseData::Pointer> Load(const std::string &path, const IFileReader::Options &options);
219 
231  static DataStorage::SetOfObjects::Pointer Load(const std::vector<std::string> &paths, DataStorage &storage);
232 
233  static std::vector<BaseData::Pointer> Load(const std::vector<std::string> &paths);
234 
245  DEPRECATED(static int LoadFiles(const std::vector<std::string> &fileNames, DataStorage &storage));
246 
258  DEPRECATED(static DataStorage::Pointer LoadFiles(const std::vector<std::string> &fileNames));
259 
268  DEPRECATED(static mitk::BaseData::Pointer LoadBaseData(const std::string &path));
269 
279  DEPRECATED(static mitk::DataNode::Pointer LoadDataNode(const std::string &path));
280 
287  static mitk::Image::Pointer LoadImage(const std::string &path);
288 
295  static mitk::Surface::Pointer LoadSurface(const std::string &path);
296 
303  static mitk::PointSet::Pointer LoadPointSet(const std::string &path);
304 
314  static std::vector<BaseData::Pointer> Load(const us::ModuleResource &usResource,
315  std::ios_base::openmode mode = std::ios_base::in);
316 
326  static void Save(const mitk::BaseData *data, const std::string &path);
327 
338  static void Save(const mitk::BaseData *data, const std::string &path, const IFileWriter::Options &options);
339 
352  static void Save(const mitk::BaseData *data,
353  const std::string &mimeType,
354  const std::string &path,
355  bool addExtension = true);
356 
370  static void Save(const mitk::BaseData *data,
371  const std::string &mimeType,
372  const std::string &path,
373  const mitk::IFileWriter::Options &options,
374  bool addExtension = true);
375 
386  static void Save(std::vector<SaveInfo> &saveInfos);
387 
398  DEPRECATED(static bool SaveImage(mitk::Image::Pointer image, const std::string &path));
399 
410  DEPRECATED(static bool SaveBaseData(mitk::BaseData *data, const std::string &path));
411 
422  DEPRECATED(static bool SaveSurface(mitk::Surface::Pointer surface, const std::string &path));
423 
433  DEPRECATED(static bool SavePointSet(mitk::PointSet::Pointer pointset, const std::string &path));
434 
435  protected:
437  {
438  virtual bool operator()(LoadInfo &loadInfo) = 0;
439  };
440 
442  {
443  virtual bool operator()(SaveInfo &saveInfo) = 0;
444  };
445 
446  static std::string Load(std::vector<LoadInfo> &loadInfos,
447  DataStorage::SetOfObjects *nodeResult,
448  DataStorage *ds,
449  ReaderOptionsFunctorBase *optionsCallback);
450 
451  static std::string Save(const BaseData *data,
452  const std::string &mimeType,
453  const std::string &path,
454  WriterOptionsFunctorBase *optionsCallback,
455  bool addExtension);
456 
457  static std::string Save(std::vector<SaveInfo> &saveInfos, WriterOptionsFunctorBase *optionsCallback);
458 
459  private:
460  struct Impl;
461  };
462 }
463 
464 #endif // MITKIOUTIL_H
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
#define MITKCORE_EXPORT
FileWriterSelector m_WriterSelector
Contains a set of IFileWriter objects.
Definition: mitkIOUtil.h:74
itk::VectorContainer< unsigned int, mitk::DataNode::Pointer > SetOfObjects
A Container of objects that is used as a result set of GetSubset() query operations (Set of...
Base of all data objects.
Definition: mitkBaseData.h:39
DataCollection - Class to facilitate loading/accessing structured data.
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:73
const BaseData * m_BaseData
The BaseData object to save.
Definition: mitkIOUtil.h:71
std::vector< BaseData::Pointer > m_Output
Definition: mitkIOUtil.h:58
#define DEPRECATED(func)
Definition: mitkCommon.h:183
MimeType m_MimeType
The selected mime-type, used to restrict results from FileWriterSelector.
Definition: mitkIOUtil.h:76
A utility class to load and save data from/to the local file system.
Definition: mitkIOUtil.h:50
std::string m_Path
Definition: mitkIOUtil.h:57
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
Definition: mitkMimeType.h:45
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:80
FileReaderSelector m_ReaderSelector
Definition: mitkIOUtil.h:60
std::string m_Path
The path to write the BaseData object to.
Definition: mitkIOUtil.h:78
static void SaveImage(std::string fileName, mitk::Image *image, std::string fileType)
Save images according to file type.