Medical Imaging Interaction Toolkit  2018.4.99-064ad45c
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 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 43 of file mitkIOUtil.h.

Member Function Documentation

◆ CreateTemporaryDirectory()

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.

Definition at line 458 of file mitkIOUtil.cpp.

References GetDirectorySeparator(), GetLastErrorStr(), GetTempPath(), mitkThrow, and mkdtemps_compat().

Referenced by mitk::ClaronTrackingDevice::ClaronTrackingDevice(), mitk::NavigationToolWriter::DoWrite(), mitk::NavigationToolStorageDeserializer::NavigationToolStorageDeserializer(), and mitk::NavigationToolStorageSerializer::NavigationToolStorageSerializer().

◆ CreateTemporaryFile() [1/3]

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 consective '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.

Definition at line 413 of file mitkIOUtil.cpp.

Referenced by CreateTemporaryFile(), mitk::AbstractFileWriter::LocalFile::GetFileName(), mitk::AbstractFileReader::GetLocalFileName(), mitkPlanarFigureIOTest(), and TestStreamMethods().

◆ CreateTemporaryFile() [2/3]

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 {code}std::ios_base::out | std::ios_base::trunc{code}.

The templateName argument must contain six consective '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.

Definition at line 418 of file mitkIOUtil.cpp.

References GetLastErrorStr(), GetTempPath(), mitkThrow, and mkstemps_compat().

◆ CreateTemporaryFile() [3/3]

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.

Definition at line 405 of file mitkIOUtil.cpp.

References CreateTemporaryFile().

◆ GetDirectorySeparator()

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.

Definition at line 369 of file mitkIOUtil.cpp.

Referenced by CreateTemporaryDirectory(), mitk::SceneIO::LoadScene(), mitk::SceneIO::LoadSceneUnzipped(), mitk::PointSetSerializer::Serialize(), mitk::SurfaceSerializer::Serialize(), mitk::GeometryDataSerializer::Serialize(), and mitk::NavigationToolStorageSerializer::Serialize().

◆ GetProgramPath()

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.

Definition at line 356 of file mitkIOUtil.cpp.

Referenced by mitk::RenderingTestHelper::ArgcHelperClass::ArgcHelperClass(), MitkCoreActivator::Load(), and mkdtemps_compat().

◆ GetTempPath()

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

Get the default temporary path.

Returns
The default path for temporary data.

Definition at line 378 of file mitkIOUtil.cpp.

References GetLastErrorStr(), and mitkThrow.

Referenced by CreateTemporaryDirectory(), CreateTemporaryFile(), mitk::NavigationToolReader::NavigationToolReader(), and mitk::NavigationToolStorageDeserializer::NavigationToolStorageDeserializer().

◆ Load() [1/11]

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&)
Examples:
Step1.cpp, Step2.cpp, Step3.cpp, Step4.cpp, Step5.cpp, and Step6.cpp.

Definition at line 489 of file mitkIOUtil.cpp.

Referenced by mitk::RenderingTestHelper::AddToStorage(), createTextAnnotationWithLayouter(), Step6::Load(), Load(), mitk::SceneReaderV1::LoadBaseDataFromDataTag(), mitk::BaseDataIO::LoadBaseDataFromFile(), mitk::LogoAnnotation::LoadLogoImageFromPath(), main(), mkdtemps_compat(), QmitkIGTPlayerWidget::OnOpenFileButtonPressed(), QmitkIGTPlayerWidget::OnPlayButtonClicked(), and ReadMitkProjectImageAndMask().

◆ Load() [2/11]

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&)

Definition at line 496 of file mitkIOUtil.cpp.

References Load(), and mitkThrow.

◆ Load() [3/11]

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&)

Definition at line 512 of file mitkIOUtil.cpp.

References Load().

◆ Load() [4/11]

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

Definition at line 269 of file mitkIOUtil.h.

◆ Load() [5/11]

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&)

Definition at line 519 of file mitkIOUtil.cpp.

References Load(), and mitkThrow.

◆ Load() [6/11]

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

Definition at line 291 of file mitkIOUtil.h.

References Json::in().

◆ Load() [7/11]

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.

Definition at line 532 of file mitkIOUtil.cpp.

References Load(), and mitkThrow.

◆ Load() [8/11]

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

Definition at line 548 of file mitkIOUtil.cpp.

References Load(), and mitkThrow.

◆ Load() [9/11]

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 respresents one object.
Exceptions
mitk::Exceptionif no reader was found for the stream.

Definition at line 745 of file mitkIOUtil.cpp.

References mitk::CoreServices::GetMimeTypeProvider(), mitk::IMimeTypeProvider::GetMimeTypesForFile(), mitk::FileReaderRegistry::GetReader(), mitk::FileReaderRegistry::GetReferences(), us::ModuleResource::GetResourcePath(), mitkThrow, mitk::IFileReader::Read(), and mitk::IFileReader::SetInput().

◆ Load() [10/11]

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 329 of file mitkIOUtil.h.

◆ Load() [11/11]

◆ Save() [1/7]

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

◆ Save() [2/7]

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.
Exceptions
mitk::Exceptionif no writer for data is available or the writer is not able to write the image.

Definition at line 775 of file mitkIOUtil.cpp.

References Save().

◆ Save() [3/7]

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.
Exceptions
mitk::Exceptionif no writer for the combination of data and mimeType is available or the writer is not able to write the image.

Definition at line 780 of file mitkIOUtil.cpp.

References Save().

◆ Save() [4/7]

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.
Exceptions
mitk::Exceptionif no writer for the combination of data and mimeType is available or the writer is not able to write the image.

Definition at line 785 of file mitkIOUtil.cpp.

References mitk::BaseData::IsEmpty(), mitkThrow, and Save().

◆ Save() [5/7]

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.
See also
Save(const mitk::BaseData*, const std::string&)

Definition at line 812 of file mitkIOUtil.cpp.

References mitkThrow, and Save().

◆ Save() [6/7]

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

◆ Save() [7/7]


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