Medical Imaging Interaction Toolkit  2016.11.0
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)
 Load a file into the given DataStorage. More...
 
static DataStorage::SetOfObjects::Pointer Load (const std::string &path, const IFileReader::Options &options, DataStorage &storage)
 
static std::vector< BaseData::PointerLoad (const std::string &path)
 
static std::vector< BaseData::PointerLoad (const std::string &path, const IFileReader::Options &options)
 
static DataStorage::SetOfObjects::Pointer Load (const std::vector< std::string > &paths, DataStorage &storage)
 Loads a list of file paths into the given DataStorage. More...
 
static std::vector< BaseData::PointerLoad (const std::vector< std::string > &paths)
 
static int LoadFiles (const std::vector< std::string > &fileNames, DataStorage &storage)
 
static DataStorage::Pointer LoadFiles (const std::vector< std::string > &fileNames)
 
static mitk::BaseData::Pointer LoadBaseData (const std::string &path)
 Create a BaseData object from the given file. More...
 
static mitk::DataNode::Pointer LoadDataNode (const std::string &path)
 LoadDataNode Method to load an arbitrary DataNode. More...
 
static mitk::Image::Pointer LoadImage (const std::string &path)
 LoadImage Convenience method to load an arbitrary mitkImage. More...
 
static mitk::Surface::Pointer LoadSurface (const std::string &path)
 LoadSurface Convenience method to load an arbitrary mitkSurface. More...
 
static mitk::PointSet::Pointer LoadPointSet (const std::string &path)
 LoadPointSet Convenience method to load an arbitrary mitkPointSet. More...
 
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...
 
static void Save (const mitk::BaseData *data, const std::string &path)
 Save a mitk::BaseData instance. More...
 
static void Save (const mitk::BaseData *data, const std::string &path, const IFileWriter::Options &options)
 Save a mitk::BaseData instance. More...
 
static void Save (const mitk::BaseData *data, const std::string &mimeType, const std::string &path, bool addExtension=true)
 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)
 Save a mitk::BaseData instance. More...
 
static void Save (std::vector< SaveInfo > &saveInfos)
 Use SaveInfo objects to save BaseData instances. More...
 
static bool SaveImage (mitk::Image::Pointer image, const std::string &path)
 SaveImage Convenience method to save an arbitrary mitkImage. More...
 
static bool SaveBaseData (mitk::BaseData *data, const std::string &path)
 SaveBaseData Convenience method to save arbitrary baseData. More...
 
static bool SaveSurface (mitk::Surface::Pointer surface, const std::string &path)
 SaveSurface Convenience method to save an arbitrary mitkSurface. More...
 
static bool SavePointSet (mitk::PointSet::Pointer pointset, const std::string &path)
 SavePointSet Convenience method to save an mitkPointSet. More...
 

Static Protected Member Functions

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

Detailed Description

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

The methods LoadImage, LoadSurface, and LoadPointSet are convenience methods for general loading of the three main data types in MITK. They all use the more generic method Load().

See also
QmitkIOUtil

Definition at line 50 of file mitkIOUtil.h.

Member Function Documentation

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 452 of file mitkIOUtil.cpp.

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

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

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 407 of file mitkIOUtil.cpp.

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

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 412 of file mitkIOUtil.cpp.

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

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 399 of file mitkIOUtil.cpp.

References CreateTemporaryFile().

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 363 of file mitkIOUtil.cpp.

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

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 350 of file mitkIOUtil.cpp.

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

std::string mitk::IOUtil::GetTempPath ( )
static
DataStorage::SetOfObjects::Pointer mitk::IOUtil::Load ( const std::string &  path,
DataStorage storage 
)
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.
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 483 of file mitkIOUtil.cpp.

Referenced by mitk::RenderingTestHelper::AddToStorage(), compute_statistics(), mitk::TrackingVolumeGenerator::GenerateData(), Step6::Load(), Load(), mitk::SceneReaderV1::LoadBaseDataFromDataTag(), mitk::BaseDataIO::LoadBaseDataFromFile(), LoadFib(), LoadFiles(), main(), QmitkNavigationToolCreationWidget::OnLoadSurface(), and ReadMitkProjectImageAndMask().

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

Definition at line 490 of file mitkIOUtil.cpp.

References Load(), mitkThrow, and mitk::New().

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

Definition at line 506 of file mitkIOUtil.cpp.

References Load().

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

Definition at line 513 of file mitkIOUtil.cpp.

References Load(), and mitkThrow.

DataStorage::SetOfObjects::Pointer mitk::IOUtil::Load ( const std::vector< std::string > &  paths,
DataStorage storage 
)
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.
Returns
The set of added DataNode objects.
Exceptions
mitk::Exceptionif an entry in paths could not be loaded.

Definition at line 526 of file mitkIOUtil.cpp.

References Load(), mitkThrow, and mitk::New().

std::vector< BaseData::Pointer > mitk::IOUtil::Load ( const std::vector< std::string > &  paths)
static

Definition at line 542 of file mitkIOUtil.cpp.

References Load(), and mitkThrow.

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 795 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().

BaseData::Pointer mitk::IOUtil::LoadBaseData ( const std::string &  path)
static

Create a BaseData object from the given file.

Parameters
pathThe path to the file including file name and file extension.
Exceptions
mitk::ExceptionIn case of an error when reading the file.
Returns
Returns the created BaseData object.
Deprecated:
(as of 2014_10) Use Load() or FileReaderRegistry::Read() instead.

Definition at line 576 of file mitkIOUtil.cpp.

Referenced by main(), QmitkIGTPlayerWidget::OnOpenFileButtonPressed(), and QmitkIGTPlayerWidget::OnPlayButtonClicked().

DataNode::Pointer mitk::IOUtil::LoadDataNode ( const std::string &  path)
static

LoadDataNode Method to load an arbitrary DataNode.

Parameters
pathThe path to the file including file name and file extension.
Exceptions
mitk::ExceptionThis exception is thrown when the DataNodeFactory is not able to read/find the file or the DataNode is NULL.
Returns
Returns the DataNode.
Deprecated:
(as of 2014_10) Use Load() instead.

Definition at line 586 of file mitkIOUtil.cpp.

References mitk::DataNode::New().

Referenced by FiberJoin(), and main().

int mitk::IOUtil::LoadFiles ( const std::vector< std::string > &  fileNames,
DataStorage storage 
)
static

Load files in fileNames and add the constructed mitk::DataNode instances to the mitk::DataStorage storage

Parameters
fileNamesA list (vector) of absolute file name paths.
storageThe data storage to which the constructed data nodes are added.
Returns
The number of added mitk::DataNode instances.
Deprecated:
(as of 2014_10) Use Load() instead

Definition at line 564 of file mitkIOUtil.cpp.

References Load().

DataStorage::Pointer mitk::IOUtil::LoadFiles ( const std::vector< std::string > &  fileNames)
static

This method will create a new mitk::DataStorage instance and pass it to LoadFiles(std::vector<std::string>,DataStorage).

Parameters
fileNamesA list (vector) of absolute file name paths.
Returns
The new mitk::DataStorage containing the constructed data nodes.
See also
LoadFiles(std::vector<std::string>,DataStorage)
Deprecated:
(as of 2014_10) Use Load() instead

Definition at line 569 of file mitkIOUtil.cpp.

References Load(), and mitk::StandaloneDataStorage::New().

PointSet::Pointer mitk::IOUtil::LoadPointSet ( const std::string &  path)
static

LoadPointSet Convenience method to load an arbitrary mitkPointSet.

Parameters
pathThe path to the pointset including file name and file extension (currently, only .mps is supported).
Exceptions
mitk::ExceptionThis exception is thrown when the PointSet is NULL.
Returns
Returns the mitkPointSet.

Definition at line 619 of file mitkIOUtil.cpp.

References mitkThrow.

Referenced by main(), QmitkPointListWidget::OnBtnLoadPoints(), and ReaderLocaleTest().

Surface::Pointer mitk::IOUtil::LoadSurface ( const std::string &  path)
static

LoadSurface Convenience method to load an arbitrary mitkSurface.

Parameters
pathThe path to the surface including file name and file extension.
Exceptions
mitk::ExceptionThis exception is thrown when the Surface is NULL.
Returns
Returns the mitkSurface.

Definition at line 608 of file mitkIOUtil.cpp.

References mitkThrow.

Referenced by mitk::NavigationToolStorageTestHelper::CreateTestData_ComplexStorage(), and QmitkNDIConfigurationWidget::LoadSurfaceFromSTLFile().

void mitk::IOUtil::Save ( const mitk::BaseData data,
const std::string &  path 
)
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.
Exceptions
mitk::Exceptionif no writer for data is available or the writer is not able to write the image.

Definition at line 824 of file mitkIOUtil.cpp.

Referenced by mitk::ImageLiveWireContourModelFilter::DumpMaskImage(), ExtractMapsAndSave(), mitk::PlanarFigureSegmentationController::GetInterpolationResult(), KurtosisMapComputation(), main(), mitkImageDimensionConverterTest(), mitkPointSetLocaleTest(), mitkSurfaceVtkWriterTest(), QmitkPointListWidget::OnBtnSavePoints(), Save(), SaveBaseData(), SaveImage(), SaveImage(), mitk::USImageLoggingFilter::SaveImages(), SavePointSet(), mitk::TumorInvasionClassification::SaveRandomForest(), SaveSurface(), mitk::VigraRandomForestClassifierSerializer::Serialize(), mitk::PointSetSerializer::Serialize(), mitk::ExampleDataStructureSerializer::Serialize(), mitk::SimulationSerializer::Serialize(), mitk::FiberBundleSerializer::Serialize(), mitk::LabelSetImageSerializer::Serialize(), mitk::SurfaceSerializer::Serialize(), mitk::PlanarFigureCompositeSerializer::Serialize(), mitk::ImageSerializer::Serialize(), mitk::GeometryDataSerializer::Serialize(), StartPeakExtraction(), StartShConversion(), mitk::TeemDiffusionTensor3DReconstructionImageFilter< DiffusionImagePixelType, TTensorPixelType >::Update(), and WriterLocaleTest().

void mitk::IOUtil::Save ( const mitk::BaseData data,
const std::string &  path,
const IFileWriter::Options options 
)
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 825 of file mitkIOUtil.cpp.

References Save().

void mitk::IOUtil::Save ( const mitk::BaseData data,
const std::string &  mimeType,
const std::string &  path,
bool  addExtension = true 
)
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 830 of file mitkIOUtil.cpp.

References Save().

void mitk::IOUtil::Save ( const mitk::BaseData data,
const std::string &  mimeType,
const std::string &  path,
const mitk::IFileWriter::Options options,
bool  addExtension = true 
)
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 835 of file mitkIOUtil.cpp.

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

void mitk::IOUtil::Save ( std::vector< SaveInfo > &  saveInfos)
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 861 of file mitkIOUtil.cpp.

References mitkThrow, and Save().

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

SaveBaseData Convenience method to save arbitrary baseData.

Parameters
pathThe path to the image including file name and file extension. If no extention is set, the default extension is used.
dataThe data to save.
Exceptions
mitk::ExceptionThis exception is thrown when the writer is not able to write the image.
Returns
Returns true for success else false.
Deprecated:
(as of 2014_10) Use Save() instead.

Definition at line 888 of file mitkIOUtil.cpp.

References Save().

Referenced by FiberJoin(), main(), and QmitkIGTLoggerWidget::StopRecording().

bool mitk::IOUtil::SaveImage ( mitk::Image::Pointer  image,
const std::string &  path 
)
static

SaveImage Convenience method to save an arbitrary mitkImage.

Parameters
pathThe path to the image including file name and file extension. If no extention is set, the default value (defined in DEFAULTIMAGEEXTENSION) is used.
imageThe image to save.
Exceptions
mitk::ExceptionThis exception is thrown when the writer is not able to write the image.
Returns
Returns true for success else false.
Deprecated:
(as of 2014_10) Use Save() instead.

Definition at line 870 of file mitkIOUtil.cpp.

References Save().

Referenced by CopyResources(), mitk::CollectionWriter::ExportCollectionToFolder(), main(), Normalize(), and mitk::CollectionWriter::SaveCollection().

bool mitk::IOUtil::SavePointSet ( mitk::PointSet::Pointer  pointset,
const std::string &  path 
)
static

SavePointSet Convenience method to save an mitkPointSet.

Parameters
pathThe path to the pointset including file name and file extension. If no extention is set, the default extension is used.
Exceptions
mitk::ExceptionThis exception is thrown when the writer is not able to write the pointset.
Returns
Returns true for success else false.
Deprecated:
(as of 2014_10) Use Save() instead.

Definition at line 882 of file mitkIOUtil.cpp.

References Save().

bool mitk::IOUtil::SaveSurface ( mitk::Surface::Pointer  surface,
const std::string &  path 
)
static

SaveSurface Convenience method to save an arbitrary mitkSurface.

Parameters
pathThe path to the surface including file name and file extension. If no extention is set, the default extension is used.
Exceptions
mitk::ExceptionThis exception is thrown when the writer is not able to write the surface. or if the fileextension is not suitable for writing.
Returns
Returns true for success else false.
Deprecated:
(as of 2014_10) Use Save() instead.

Definition at line 876 of file mitkIOUtil.cpp.

References Save().

Referenced by main().


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