Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
Medical Imaging Interaction Toolkit
mitk::IOUtil Class Reference

A utility class to load and save data from/to the local file system. More...

#include <mitkIOUtil.h>

Inheritance diagram for mitk::IOUtil:

Classes

struct  LoadInfo
 
struct  ReaderOptionsFunctorBase
 
struct  SaveInfo
 
struct  WriterOptionsFunctorBase
 

Static Public Member Functions

static std::string GetProgramPath ()
 
static std::string GetTempPath ()
 
static char GetDirectorySeparator ()
 
static std::string CreateTemporaryFile (std::ofstream &tmpStream, const std::string &templateName="XXXXXX", std::string path=std::string())
 
static std::string CreateTemporaryFile (std::ofstream &tmpStream, std::ios_base::openmode mode, const std::string &templateName="XXXXXX", std::string path=std::string())
 
static std::string CreateTemporaryFile (const std::string &templateName="XXXXXX", std::string path=std::string())
 
static std::string CreateTemporaryDirectory (const std::string &templateName="XXXXXX", std::string path=std::string())
 
static DataStorage::SetOfObjects::Pointer Load (const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
 Load a file into the given DataStorage. More...
 
static DataStorage::SetOfObjects::Pointer Load (const std::string &path, const IFileReader::Options &options, DataStorage &storage)
 Load a file into the given DataStorage given user defined IFileReader::Options. More...
 
static std::vector< BaseData::PointerLoad (const std::string &path, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
 Load a file and return the loaded data. More...
 
template<typename T >
static T::Pointer Load (const std::string &path, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
 
static std::vector< BaseData::PointerLoad (const std::string &path, const IFileReader::Options &options)
 Load a file and return the loaded data. More...
 
template<typename T >
static T::Pointer Load (const std::string &path, const IFileReader::Options &options)
 
static DataStorage::SetOfObjects::Pointer Load (const std::vector< std::string > &paths, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
 Loads a list of file paths into the given DataStorage. More...
 
static std::vector< BaseData::PointerLoad (const std::vector< std::string > &paths, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
 
static std::vector< BaseData::PointerLoad (const us::ModuleResource &usResource, std::ios_base::openmode mode=std::ios_base::in)
 Loads the contents of a us::ModuleResource and returns the corresponding mitk::BaseData. More...
 
template<typename T >
static T::Pointer Load (const us::ModuleResource &usResource, std::ios_base::openmode mode=std::ios_base::in)
 
static BaseData::Pointer Load (const std::string &path, const PropertyList *properties)
 
static void Save (const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
 Save a mitk::BaseData instance. More...
 
static void Save (const mitk::BaseData *data, const std::string &path, const IFileWriter::Options &options, bool setPathProperty=false)
 Save a mitk::BaseData instance. More...
 
static void Save (const mitk::BaseData *data, const std::string &mimeType, const std::string &path, bool addExtension=true, bool setPathProperty=false)
 Save a mitk::BaseData instance. More...
 
static void Save (const mitk::BaseData *data, const std::string &mimeType, const std::string &path, const mitk::IFileWriter::Options &options, bool addExtension=true, bool setPathProperty=false)
 Save a mitk::BaseData instance. More...
 
static void Save (std::vector< SaveInfo > &saveInfos, bool setPathProperty=false)
 Use SaveInfo objects to save BaseData instances. More...
 

Static Protected Member Functions

static std::string Load (std::vector< LoadInfo > &loadInfos, DataStorage::SetOfObjects *nodeResult, DataStorage *ds, const ReaderOptionsFunctorBase *optionsCallback)
 
static std::string Save (const BaseData *data, const std::string &mimeType, const std::string &path, WriterOptionsFunctorBase *optionsCallback, bool addExtension, bool setPathProperty)
 
static std::string Save (std::vector< SaveInfo > &saveInfos, WriterOptionsFunctorBase *optionsCallback, bool setPathProperty)
 

Detailed Description

A utility class to load and save data from/to the local file system.

See also
QmitkIOUtil

Definition at line 49 of file mitkIOUtil.h.

Member Function Documentation

◆ CreateTemporaryDirectory()

static std::string mitk::IOUtil::CreateTemporaryDirectory ( const std::string &  templateName = "XXXXXX",
std::string  path = std::string() 
)
static

Create a temporary directory.

This method generates a uniquely named temporary directory from templateName. The last set of six consecutive 'X' characters in templateName is replaced with a string that makes the directory name unique.

The directory is created with read, write and executable permissions for owner only.

Parameters
templateNameAn optional template for the directory name.
pathAn optional path where the temporary directory should be created. Defaults to the default temp path as returned by GetTempPath().
Returns
The filename of the created temporary file.
Exceptions
mitk::Exceptionif the temporary directory could not be created.

◆ CreateTemporaryFile() [1/3]

static std::string mitk::IOUtil::CreateTemporaryFile ( const std::string &  templateName = "XXXXXX",
std::string  path = std::string() 
)
static

Creates an empty temporary file.

This method generates a unique temporary filename from templateName and creates this file.

The file is created with read and write permissions for owner only.


This version is potentially unsafe because the created temporary file is not kept open and could be used by another process between calling this method and opening the returned

file path for reading or writing.

Returns
The filename of the created temporary file.
Parameters
templateNameAn optional template for the filename.
pathAn optional path where the temporary file should be created. Defaults to the default temp path as returned by GetTempPath().
Exceptions
mitk::Exceptionif the temporary file could not be created.

◆ CreateTemporaryFile() [2/3]

static std::string mitk::IOUtil::CreateTemporaryFile ( std::ofstream &  tmpStream,
const std::string &  templateName = "XXXXXX",
std::string  path = std::string() 
)
static

Create and open a temporary file.

This method generates a unique temporary filename from templateName, creates and opens the file using the output stream tmpStream and returns the name of the newly create file.

The templateName argument must contain six consecutive 'X' characters ("XXXXXX") and these are replaced with a string that makes the filename unique.

The file is created with read and write permissions for owner only.

Parameters
tmpStreamThe output stream for writing to the temporary file.
templateNameAn optional template for the filename.
pathAn optional path where the temporary file should be created. Defaults to the default temp path as returned by GetTempPath().
Returns
The filename of the created temporary file.
Exceptions
mitk::Exceptionif the temporary file could not be created.

◆ CreateTemporaryFile() [3/3]

static std::string mitk::IOUtil::CreateTemporaryFile ( std::ofstream &  tmpStream,
std::ios_base::openmode  mode,
const std::string &  templateName = "XXXXXX",
std::string  path = std::string() 
)
static

Create and open a temporary file.

This method generates a unique temporary filename from templateName, creates and opens the file using the output stream tmpStream and the specified open mode mode and returns the name of the newly create file. The open mode is always OR'd with std::ios_base::out | std::ios_base::trunc.

The templateName argument must contain six consecutive 'X' characters ("XXXXXX") and these are replaced with a string that makes the filename unique.

The file is created with read and write permissions for owner only.

Parameters
tmpStreamThe output stream for writing to the temporary file.
modeThe open mode for the temporary file stream.
templateNameAn optional template for the filename.
pathAn optional path where the temporary file should be created. Defaults to the default temp path as returned by GetTempPath().
Returns
The filename of the created temporary file.
Exceptions
mitk::Exceptionif the temporary file could not be created.

◆ GetDirectorySeparator()

static char mitk::IOUtil::GetDirectorySeparator ( )
static

Returns the Directory Seperator for the current OS.

Returns
the Directory Seperator for the current OS, i.e. "\\" for Windows and "/" otherwise.

◆ GetProgramPath()

static std::string mitk::IOUtil::GetProgramPath ( )
static

Get the file system path where the running executable is located.

Returns
The location of the currently running executable, without the filename.

Referenced by mitk::RenderingTestHelper::ArgcHelperClass::ArgcHelperClass().

◆ GetTempPath()

static std::string mitk::IOUtil::GetTempPath ( )
static

Get the default temporary path.

Returns
The default path for temporary data.

◆ Load() [1/12]

static std::vector<BaseData::Pointer> mitk::IOUtil::Load ( const std::string &  path,
const IFileReader::Options options 
)
static

Load a file and return the loaded data.

This method calls Load(const std::vector<std::string>&) with a one-element vector.

Parameters
pathThe absolute file name including the file extension.
optionsIFileReader option instance that should be used if selected reader has options.
Returns
The set of added DataNode objects.
Exceptions
mitk::Exceptionif path could not be loaded.
See also
Load(const std::vector<std::string>&, DataStorage&)

◆ Load() [2/12]

template<typename T >
static T::Pointer mitk::IOUtil::Load ( const std::string &  path,
const IFileReader::Options options 
)
inlinestatic

Definition at line 299 of file mitkIOUtil.h.

◆ Load() [3/12]

static DataStorage::SetOfObjects::Pointer mitk::IOUtil::Load ( const std::string &  path,
const IFileReader::Options options,
DataStorage storage 
)
static

Load a file into the given DataStorage given user defined IFileReader::Options.

This method calls Load(const std::vector<std::string>&, DataStorage&) with a one-element vector.

Parameters
pathThe absolute file name including the file extension.
optionsIFileReader option instance that should be used if selected reader has options.
storageA DataStorage object to which the loaded data will be added.
Returns
The set of added DataNode objects.
Exceptions
mitk::Exceptionif path could not be loaded.
See also
Load(const std::vector<std::string>&, DataStorage&)

◆ Load() [4/12]

static BaseData::Pointer mitk::IOUtil::Load ( const std::string &  path,
const PropertyList properties 
)
static

◆ Load() [5/12]

static std::vector<BaseData::Pointer> mitk::IOUtil::Load ( const std::string &  path,
const ReaderOptionsFunctorBase optionsCallback = nullptr 
)
static

Load a file and return the loaded data.

This method calls Load(const std::vector<std::string>&) with a one-element vector.

Parameters
pathThe absolute file name including the file extension.
optionsCallbackPointer to a callback instance. The callback is used by the load operation if more the suitable reader was found or the reader has options that can be set.
Returns
The set of added DataNode objects.
Exceptions
mitk::Exceptionif path could not be loaded.
See also
Load(const std::vector<std::string>&, DataStorage&)

◆ Load() [6/12]

template<typename T >
static T::Pointer mitk::IOUtil::Load ( const std::string &  path,
const ReaderOptionsFunctorBase optionsCallback = nullptr 
)
inlinestatic

Definition at line 277 of file mitkIOUtil.h.

◆ Load() [7/12]

static DataStorage::SetOfObjects::Pointer mitk::IOUtil::Load ( const std::string &  path,
DataStorage storage,
const ReaderOptionsFunctorBase optionsCallback = nullptr 
)
static

Load a file into the given DataStorage.

This method calls Load(const std::vector<std::string>&, DataStorage&) with a one-element vector.

Parameters
pathThe absolute file name including the file extension.
storageA DataStorage object to which the loaded data will be added.
optionsCallbackPointer to a callback instance. The callback is used by the load operation if more the suitable reader was found or the reader has options that can be set.
Returns
The set of added DataNode objects.
Exceptions
mitk::Exceptionif path could not be loaded.
See also
Load(const std::vector<std::string>&, DataStorage&)

◆ Load() [8/12]

static std::vector<BaseData::Pointer> mitk::IOUtil::Load ( const std::vector< std::string > &  paths,
const ReaderOptionsFunctorBase optionsCallback = nullptr 
)
static

◆ Load() [9/12]

static DataStorage::SetOfObjects::Pointer mitk::IOUtil::Load ( const std::vector< std::string > &  paths,
DataStorage storage,
const ReaderOptionsFunctorBase optionsCallback = nullptr 
)
static

Loads a list of file paths into the given DataStorage.

If an entry in paths cannot be loaded, this method will continue to load the remaining entries into storage and throw an exception afterwards.

Parameters
pathsA list of absolute file names including the file extension.
storageA DataStorage object to which the loaded data will be added.
optionsCallbackPointer to a callback instance. The callback is used by the load operation if more the suitable reader was found or the reader has options that can be set.
Returns
The set of added DataNode objects.
Exceptions
mitk::Exceptionif an entry in paths could not be loaded.

◆ Load() [10/12]

static std::vector<BaseData::Pointer> mitk::IOUtil::Load ( const us::ModuleResource usResource,
std::ios_base::openmode  mode = std::ios_base::in 
)
static

Loads the contents of a us::ModuleResource and returns the corresponding mitk::BaseData.

Parameters
usResourcea ModuleResource, representing a BaseData object
modeOptional parameter to set the openmode of the stream
Returns
The set of loaded BaseData objects. Should contain either one or zero elements, since a resource stream represents one object.
Exceptions
mitk::Exceptionif no reader was found for the stream.

◆ Load() [11/12]

template<typename T >
static T::Pointer mitk::IOUtil::Load ( const us::ModuleResource usResource,
std::ios_base::openmode  mode = std::ios_base::in 
)
inlinestatic

Definition at line 337 of file mitkIOUtil.h.

◆ Load() [12/12]

static std::string mitk::IOUtil::Load ( std::vector< LoadInfo > &  loadInfos,
DataStorage::SetOfObjects nodeResult,
DataStorage ds,
const ReaderOptionsFunctorBase optionsCallback 
)
staticprotected

◆ Save() [1/7]

static std::string mitk::IOUtil::Save ( const BaseData data,
const std::string &  mimeType,
const std::string &  path,
WriterOptionsFunctorBase optionsCallback,
bool  addExtension,
bool  setPathProperty 
)
staticprotected

◆ Save() [2/7]

static void mitk::IOUtil::Save ( const mitk::BaseData data,
const std::string &  mimeType,
const std::string &  path,
bool  addExtension = true,
bool  setPathProperty = false 
)
static

Save a mitk::BaseData instance.

Parameters
dataThe data to save.
mimeTypeThe mime-type to use for writing data.
pathThe path to the image including file name and an optional file extension.
addExtensionIf true, an extension according to the given mimeType is added to path if it does not contain one. If path already contains a file name extension, it is not checked for compatibility with mimeType.
setPathProperty
Exceptions
mitk::Exceptionif no writer for the combination of data and mimeType is available or the writer is not able to write the image.

◆ Save() [3/7]

static void mitk::IOUtil::Save ( const mitk::BaseData data,
const std::string &  mimeType,
const std::string &  path,
const mitk::IFileWriter::Options options,
bool  addExtension = true,
bool  setPathProperty = false 
)
static

Save a mitk::BaseData instance.

Parameters
dataThe data to save.
mimeTypeThe mime-type to use for writing data.
pathThe path to the image including file name and an optional file extension.
optionsConfiguration data for the used IFileWriter instance.
addExtensionIf true, an extension according to the given mimeType is added to path if it does not contain one. If path already contains a file name extension, it is not checked for compatibility with mimeType.
setPathProperty
Exceptions
mitk::Exceptionif no writer for the combination of data and mimeType is available or the writer is not able to write the image.

◆ Save() [4/7]

static void mitk::IOUtil::Save ( const mitk::BaseData data,
const std::string &  path,
bool  setPathProperty = false 
)
static

Save a mitk::BaseData instance.

Parameters
dataThe data to save.
pathThe path to the image including file name and and optional file extension. If no extension is set, the default extension and mime-type for the BaseData type of data is used.
setPathProperty
Exceptions
mitk::Exceptionif no writer for data is available or the writer is not able to write the image.

◆ Save() [5/7]

static void mitk::IOUtil::Save ( const mitk::BaseData data,
const std::string &  path,
const IFileWriter::Options options,
bool  setPathProperty = false 
)
static

Save a mitk::BaseData instance.

Parameters
dataThe data to save.
pathThe path to the image including file name and an optional file extension. If no extension is set, the default extension and mime-type for the BaseData type of data is used.
optionsThe IFileWriter options to use for the selected writer.
setPathProperty
Exceptions
mitk::Exceptionif no writer for data is available or the writer is not able to write the image.

◆ Save() [6/7]

static void mitk::IOUtil::Save ( std::vector< SaveInfo > &  saveInfos,
bool  setPathProperty = false 
)
static

Use SaveInfo objects to save BaseData instances.

This is a low-level method for directly working with SaveInfo objects. Usually, the Save() methods taking a BaseData object as an argument are more appropriate.

Parameters
saveInfosA list of SaveInfo objects for saving contained BaseData objects.
setPathProperty
See also
Save(const mitk::BaseData*, const std::string&)

◆ Save() [7/7]

static std::string mitk::IOUtil::Save ( std::vector< SaveInfo > &  saveInfos,
WriterOptionsFunctorBase optionsCallback,
bool  setPathProperty 
)
staticprotected

The documentation for this class was generated from the following file: