Medical Imaging Interaction Toolkit
2016.11.0
Medical Imaging Interaction Toolkit
|
A utility class to load and save data from/to the local file system. More...
#include <mitkIOUtil.h>
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::Pointer > | Load (const std::string &path) |
static std::vector< BaseData::Pointer > | Load (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::Pointer > | Load (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::Pointer > | Load (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) |
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().
Definition at line 50 of file mitkIOUtil.h.
|
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.
templateName | An optional template for the directory name. |
path | An optional path where the temporary directory should be created. Defaults to the default temp path as returned by GetTempPath(). |
mitk::Exception | if 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().
|
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.
tmpStream | The output stream for writing to the temporary file. |
templateName | An optional template for the filename. |
path | An optional path where the temporary file should be created. Defaults to the default temp path as returned by GetTempPath(). |
mitk::Exception | if 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().
|
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.
tmpStream | The output stream for writing to the temporary file. |
mode | The open mode for the temporary file stream. |
templateName | An optional template for the filename. |
path | An optional path where the temporary file should be created. Defaults to the default temp path as returned by GetTempPath(). |
mitk::Exception | if the temporary file could not be created. |
Definition at line 412 of file mitkIOUtil.cpp.
References GetLastErrorStr(), GetTempPath(), mitkThrow, and mkstemps_compat().
|
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
templateName | An optional template for the filename. |
path | An optional path where the temporary file should be created. Defaults to the default temp path as returned by GetTempPath(). |
mitk::Exception | if the temporary file could not be created. |
Definition at line 399 of file mitkIOUtil.cpp.
References CreateTemporaryFile().
|
static |
Returns the Directory Seperator for the current OS.
Definition at line 363 of file mitkIOUtil.cpp.
Referenced by CreateTemporaryDirectory(), mitk::SceneIO::LoadScene(), mitk::PointSetSerializer::Serialize(), mitk::SurfaceSerializer::Serialize(), and mitk::GeometryDataSerializer::Serialize().
|
static |
Get the file system path where the running executable is located.
Definition at line 350 of file mitkIOUtil.cpp.
Referenced by mitk::RenderingTestHelper::ArgcHelperClass::ArgcHelperClass(), MitkCoreActivator::Load(), mitk::NavigationToolStorageSerializer::NavigationToolStorageSerializer(), and mitk::PythonService::PythonService().
|
static |
Get the default temporary path.
Definition at line 372 of file mitkIOUtil.cpp.
References GetLastErrorStr(), and mitkThrow.
Referenced by CreateTemporaryDirectory(), CreateTemporaryFile(), main(), mitk::NavigationToolReader::NavigationToolReader(), mitk::NavigationToolStorageDeserializer::NavigationToolStorageDeserializer(), and itk::TractsToDWIImageFilter< PixelType >::PrepareLogFile().
|
static |
Load a file into the given DataStorage.
This method calls Load(const std::vector<std::string>&, DataStorage&) with a one-element vector.
path | The absolute file name including the file extension. |
storage | A DataStorage object to which the loaded data will be added. |
mitk::Exception | if path could not be loaded. |
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().
|
static |
Definition at line 490 of file mitkIOUtil.cpp.
References Load(), mitkThrow, and mitk::New().
|
static |
Definition at line 506 of file mitkIOUtil.cpp.
References Load().
|
static |
Definition at line 513 of file mitkIOUtil.cpp.
|
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.
paths | A list of absolute file names including the file extension. |
storage | A DataStorage object to which the loaded data will be added. |
mitk::Exception | if an entry in paths could not be loaded. |
Definition at line 526 of file mitkIOUtil.cpp.
References Load(), mitkThrow, and mitk::New().
|
static |
Definition at line 542 of file mitkIOUtil.cpp.
|
static |
Loads the contents of a us::ModuleResource and returns the corresponding mitk::BaseData.
usResource | a ModuleResource, representing a BaseData object |
mode | Optional parameter to set the openmode of the stream |
Should
contain either one or zero elements, since a resource stream respresents one object. mitk::Exception | if 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().
|
staticprotected |
Definition at line 630 of file mitkIOUtil.cpp.
References mitk::ProgressBar::AddStepsToDo(), mitk::ProgressBar::GetInstance(), mitk::FileReaderSelector::Item::GetMimeType(), mitk::MimeType::GetName(), MITK_ERROR, mitk::New(), mitk::StringProperty::New(), mitk::DataNode::New(), mitk::ProgressBar::Progress(), and mitk::IFileReader::Read().
|
static |
Create a BaseData object from the given file.
path | The path to the file including file name and file extension. |
mitk::Exception | In case of an error when reading the file. |
Definition at line 576 of file mitkIOUtil.cpp.
Referenced by main(), QmitkIGTPlayerWidget::OnOpenFileButtonPressed(), and QmitkIGTPlayerWidget::OnPlayButtonClicked().
|
static |
LoadDataNode Method to load an arbitrary DataNode.
path | The path to the file including file name and file extension. |
mitk::Exception | This exception is thrown when the DataNodeFactory is not able to read/find the file or the DataNode is NULL. |
Definition at line 586 of file mitkIOUtil.cpp.
References mitk::DataNode::New().
Referenced by FiberJoin(), and main().
|
static |
Load files in fileNames
and add the constructed mitk::DataNode instances to the mitk::DataStorage storage
fileNames | A list (vector) of absolute file name paths. |
storage | The data storage to which the constructed data nodes are added. |
Definition at line 564 of file mitkIOUtil.cpp.
References Load().
|
static |
This method will create a new mitk::DataStorage instance and pass it to LoadFiles(std::vector<std::string>,DataStorage).
fileNames | A list (vector) of absolute file name paths. |
Definition at line 569 of file mitkIOUtil.cpp.
References Load(), and mitk::StandaloneDataStorage::New().
|
static |
LoadImage Convenience method to load an arbitrary mitkImage.
path | The path to the image including file name and file extension. |
mitk::Exception | This exception is thrown when the Image is NULL. |
Definition at line 597 of file mitkIOUtil.cpp.
References mitkThrow.
Referenced by compute_statistics(), CopyResources(), ExtractImageStatistics(), mitk::CollectionReader::FolderToCollection(), ImageVtkDataReferenceCheck(), LoadPreprocessedFiles(), main(), mitkCompressedImageContainerTest(), mitkExtractSliceFilterTest(), mitkImageAccessorTest(), mitkImageDimensionConverterTest(), mitkImageSliceSelectorTest(), mitkImageTest(), mitkLabeledImageToSurfaceFilterTest(), mitkMultiComponentImageDataComparisonFilterTest(), mitkRotatedSlice4DTest(), mitkVolumeCalculatorTest(), mitk::ToFCameraMITKPlayerController::OpenCameraConnection(), Setup(), mitk::CollectionReader::StartElement(), StartPeakExtraction(), and TestDataStorage().
|
static |
LoadPointSet Convenience method to load an arbitrary mitkPointSet.
path | The path to the pointset including file name and file extension (currently, only .mps is supported). |
mitk::Exception | This exception is thrown when the PointSet is NULL. |
Definition at line 619 of file mitkIOUtil.cpp.
References mitkThrow.
Referenced by main(), QmitkPointListWidget::OnBtnLoadPoints(), and ReaderLocaleTest().
|
static |
LoadSurface Convenience method to load an arbitrary mitkSurface.
path | The path to the surface including file name and file extension. |
mitk::Exception | This exception is thrown when the Surface is NULL. |
Definition at line 608 of file mitkIOUtil.cpp.
References mitkThrow.
Referenced by mitk::NavigationToolStorageTestHelper::CreateTestData_ComplexStorage(), and QmitkNDIConfigurationWidget::LoadSurfaceFromSTLFile().
|
static |
Save a mitk::BaseData instance.
data | The data to save. |
path | The 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. |
mitk::Exception | if 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().
|
static |
Save a mitk::BaseData instance.
data | The data to save. |
path | The 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. |
options | The IFileWriter options to use for the selected writer. |
mitk::Exception | if 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().
|
static |
Save a mitk::BaseData instance.
data | The data to save. |
mimeType | The mime-type to use for writing data . |
path | The path to the image including file name and an optional file extension. |
addExtension | If 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 . |
mitk::Exception | if 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().
|
static |
Save a mitk::BaseData instance.
data | The data to save. |
mimeType | The mime-type to use for writing data . |
path | The path to the image including file name and an optional file extension. |
options | Configuration data for the used IFileWriter instance. |
addExtension | If 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 . |
mitk::Exception | if 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().
|
static |
|
staticprotected |
Definition at line 894 of file mitkIOUtil.cpp.
References mitk::MimeType::GetExtensions(), mitk::IMimeTypeProvider::GetMimeTypeForName(), mitk::CoreServices::GetMimeTypeProvider(), mitk::MimeType::GetName(), mitk::FileWriterSelector::IsEmpty(), mitk::MimeType::IsValid(), mitk::IOUtil::SaveInfo::m_MimeType, mitk::IOUtil::SaveInfo::m_WriterSelector, and Save().
|
staticprotected |
Definition at line 931 of file mitkIOUtil.cpp.
References mitk::ProgressBar::AddStepsToDo(), mitk::FileWriterSelector::Item::GetConfidenceLevel(), mitk::ProgressBar::GetInstance(), mitk::IFileIO::GetOptions(), mitk::FileWriterSelector::Item::GetServiceId(), mitk::FileWriterSelector::Item::GetWriter(), MITK_ERROR, mitk::ProgressBar::Progress(), mitk::IFileWriter::SetOutputLocation(), and mitk::IFileWriter::Write().
|
static |
SaveBaseData Convenience method to save arbitrary baseData.
path | The path to the image including file name and file extension. If no extention is set, the default extension is used. |
data | The data to save. |
mitk::Exception | This exception is thrown when the writer is not able to write the image. |
Definition at line 888 of file mitkIOUtil.cpp.
References Save().
Referenced by FiberJoin(), main(), and QmitkIGTLoggerWidget::StopRecording().
|
static |
SaveImage Convenience method to save an arbitrary mitkImage.
path | The path to the image including file name and file extension. If no extention is set, the default value (defined in DEFAULTIMAGEEXTENSION) is used. |
image | The image to save. |
mitk::Exception | This exception is thrown when the writer is not able to write the image. |
Definition at line 870 of file mitkIOUtil.cpp.
References Save().
Referenced by CopyResources(), mitk::CollectionWriter::ExportCollectionToFolder(), main(), Normalize(), and mitk::CollectionWriter::SaveCollection().
|
static |
SavePointSet Convenience method to save an mitkPointSet.
path | The path to the pointset including file name and file extension. If no extention is set, the default extension is used. |
mitk::Exception | This exception is thrown when the writer is not able to write the pointset. |
Definition at line 882 of file mitkIOUtil.cpp.
References Save().
|
static |
SaveSurface Convenience method to save an arbitrary mitkSurface.
path | The path to the surface including file name and file extension. If no extention is set, the default extension is used. |
mitk::Exception | This exception is thrown when the writer is not able to write the surface. or if the fileextension is not suitable for writing. |
Definition at line 876 of file mitkIOUtil.cpp.
References Save().
Referenced by main().