Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
mitk::AbstractFileReader Class Referenceabstract

Base class for creating mitk::BaseData objects from files or streams. More...

#include <mitkAbstractFileReader.h>

Inheritance diagram for mitk::AbstractFileReader:
Collaboration diagram for mitk::AbstractFileReader:

Classes

class  InputStream
 An input stream wrapper. More...
 

Public Member Functions

void SetInput (const std::string &location) override
 Set the input location. More...
 
void SetInput (const std::string &location, std::istream *is) override
 Set an input stream to read from. More...
 
std::string GetInputLocation () const override
 Get the current input location. More...
 
std::istream * GetInputStream () const override
 Get the input stream. More...
 
MimeType GetRegisteredMimeType () const
 
std::vector< itk::SmartPointer< BaseData > > Read () override
 Reads a path or stream and creates a list of BaseData objects. More...
 
DataStorage::SetOfObjects::Pointer Read (mitk::DataStorage &ds) override
 Reads the specified file or input stream, loading its contents into the provided DataStorage. More...
 
ConfidenceLevel GetConfidenceLevel () const override
 The confidence level of the reader or writer implementation. More...
 
Options GetOptions () const override
 returns a list of the supported options More...
 
us::Any GetOption (const std::string &name) const override
 
void SetOptions (const Options &options) override
 
void SetOption (const std::string &name, const us::Any &value) override
 
void AddProgressCallback (const ProgressCallback &callback) override
 
void RemoveProgressCallback (const ProgressCallback &callback) override
 
us::ServiceRegistration< IFileReaderRegisterService (us::ModuleContext *context=us::GetModuleContext())
 
void UnregisterService ()
 
std::vector< std::string > GetReadFiles () override
 
void SetProperties (const PropertyList *properties) override
 Optionally provide base data properties as a source of meta data. More...
 
- Public Member Functions inherited from mitk::IFileReader
 ~IFileReader () override
 
virtual ~IFileReader ()
 
- Public Member Functions inherited from mitk::IFileIO
virtual ~IFileIO ()
 

Protected Member Functions

 AbstractFileReader ()
 
 ~AbstractFileReader () override
 
 AbstractFileReader (const AbstractFileReader &other)
 
 AbstractFileReader (const CustomMimeType &mimeType, const std::string &description)
 
virtual std::vector< itk::SmartPointer< BaseData > > DoRead ()=0
 
virtual us::ServiceProperties GetServiceProperties () const
 
virtual us::ServiceRegistration< CustomMimeTypeRegisterMimeType (us::ModuleContext *context)
 
void SetMimeType (const CustomMimeType &mimeType)
 
const CustomMimeTypeGetMimeType () const
 
void SetMimeTypePrefix (const std::string &prefix)
 
std::string GetMimeTypePrefix () const
 
void SetDescription (const std::string &description)
 
std::string GetDescription () const
 
void SetDefaultOptions (const Options &defaultOptions)
 
Options GetDefaultOptions () const
 
void SetRanking (int ranking)
 Set the service ranking for this file reader. More...
 
int GetRanking () const
 
std::string GetLocalFileName () const
 Get a local file name for reading. More...
 
virtual void SetDefaultDataNodeProperties (DataNode *node, const std::string &filePath)
 
const PropertyListGetProperties () const override
 

Protected Attributes

std::vector< std::string > m_ReadFiles
 

Additional Inherited Members

- Public Types inherited from mitk::IFileIO
enum  ConfidenceLevel { Unsupported, PartiallySupported, Supported }
 A confidence level describing the confidence of the reader or writer in handling the given data. More...
 
typedef std::map< std::string, us::AnyOptions
 Options for reading or writing data. More...
 
typedef mitk::MessageAbstractDelegate1< float > ProgressCallback
 
- Static Public Member Functions inherited from mitk::IFileIO
static std::string PROP_DESCRIPTION ()
 Service property name for a description. More...
 
static std::string PROP_MIMETYPE ()
 Service property name for the mime-type associated with this file writer. More...
 

Detailed Description

Base class for creating mitk::BaseData objects from files or streams.

Definition at line 42 of file mitkAbstractFileReader.h.

Constructor & Destructor Documentation

◆ AbstractFileReader() [1/3]

mitk::AbstractFileReader::AbstractFileReader ( )
protected

◆ ~AbstractFileReader()

mitk::AbstractFileReader::~AbstractFileReader ( )
overrideprotected

◆ AbstractFileReader() [2/3]

mitk::AbstractFileReader::AbstractFileReader ( const AbstractFileReader other)
protected

◆ AbstractFileReader() [3/3]

mitk::AbstractFileReader::AbstractFileReader ( const CustomMimeType mimeType,
const std::string &  description 
)
explicitprotected

Associate this reader instance with the given MIME type.

If mimeType does not provide an extension list, an already registered mime-type object is used. Otherwise, the first entry in the extensions list is used to construct a mime-type name and register it as a new CustomMimeType service object in the default implementation of RegisterMimeType().

Parameters
mimeTypeThe mime type this reader can read.
descriptionA human readable description of this reader.
Exceptions
std::invalid_argumentif mimeType is empty.
See also
RegisterService

Member Function Documentation

◆ AddProgressCallback()

void mitk::AbstractFileReader::AddProgressCallback ( const ProgressCallback callback)
overridevirtual

Implements mitk::IFileIO.

◆ DoRead()

◆ GetConfidenceLevel()

ConfidenceLevel mitk::AbstractFileReader::GetConfidenceLevel ( ) const
overridevirtual

The confidence level of the reader or writer implementation.

Returns
Confidence level.

The level is used to rank multiple competing implementations.

Implements mitk::IFileIO.

Reimplemented in mitk::LegacyLabelSetImageIO, and mitk::BaseDICOMReaderService.

Referenced by mitk::AbstractFileIOReader::GetReaderConfidenceLevel().

◆ GetDefaultOptions()

Options mitk::AbstractFileReader::GetDefaultOptions ( ) const
protected

◆ GetDescription()

std::string mitk::AbstractFileReader::GetDescription ( ) const
protected

◆ GetInputLocation()

std::string mitk::AbstractFileReader::GetInputLocation ( ) const
overridevirtual

Get the current input location.

Returns
The input location.

Implements mitk::IFileReader.

◆ GetInputStream()

std::istream* mitk::AbstractFileReader::GetInputStream ( ) const
overridevirtual

Get the input stream.

Returns
The currently set input stream.

Implements mitk::IFileReader.

◆ GetLocalFileName()

std::string mitk::AbstractFileReader::GetLocalFileName ( ) const
protected

Get a local file name for reading.

This is a convenience method for readers which cannot work natively with input streams. If no input stream has been been set, this method just returns the result of GetLocation(). However, if SetLocation(std::string, std::istream*) has been called with a non-null input stream, this method writes the contents of the stream to a temporary file and returns the name of the temporary file.

The temporary file is deleted when either SetLocation(std::string, std::istream*) is called again with a different input stream or the destructor of this class is called.

This method does not validate file names set via SetInput(std::string).

Returns
A file path in the local file-system for reading.

◆ GetMimeType()

const CustomMimeType* mitk::AbstractFileReader::GetMimeType ( ) const
protected
Returns
The mime-type this reader can handle.

◆ GetMimeTypePrefix()

std::string mitk::AbstractFileReader::GetMimeTypePrefix ( ) const
protected

◆ GetOption()

us::Any mitk::AbstractFileReader::GetOption ( const std::string &  name) const
overridevirtual

Implements mitk::IFileIO.

◆ GetOptions()

Options mitk::AbstractFileReader::GetOptions ( ) const
overridevirtual

returns a list of the supported options

Options are strings that are treated as flags when passed to the write method.

Implements mitk::IFileIO.

◆ GetProperties()

const PropertyList* mitk::AbstractFileReader::GetProperties ( ) const
overrideprotectedvirtual
See also
SetProperties().

Implements mitk::IFileReader.

◆ GetRanking()

int mitk::AbstractFileReader::GetRanking ( ) const
protected

◆ GetReadFiles()

std::vector< std::string > mitk::AbstractFileReader::GetReadFiles ( )
overridevirtual
Returns
A list of files that were loaded during the last call of Read. Has to be filled by the actual reader class.

Implements mitk::IFileReader.

◆ GetRegisteredMimeType()

MimeType mitk::AbstractFileReader::GetRegisteredMimeType ( ) const

◆ GetServiceProperties()

virtual us::ServiceProperties mitk::AbstractFileReader::GetServiceProperties ( ) const
protectedvirtual

◆ Read() [1/2]

std::vector<itk::SmartPointer<BaseData> > mitk::AbstractFileReader::Read ( )
overridevirtual

Reads a path or stream and creates a list of BaseData objects.

The default implementation of this method (1) calls DoRead() (Implement the specific reader operation there) and (2) it adds general meta information about the loading process.

Implements mitk::IFileReader.

◆ Read() [2/2]

DataStorage::SetOfObjects::Pointer mitk::AbstractFileReader::Read ( mitk::DataStorage ds)
overridevirtual

Reads the specified file or input stream, loading its contents into the provided DataStorage.

Parameters
dsThe DataStorage to which the data is added.
Returns
The set of added DataNodes to ds.

This method may be overridden by implementations to create or reconstructed a hierarchy of mitk::DataNode instances in the provided mitk::DataStorage.

Exceptions
mitk::Exception

Implements mitk::IFileReader.

◆ RegisterMimeType()

virtual us::ServiceRegistration<CustomMimeType> mitk::AbstractFileReader::RegisterMimeType ( us::ModuleContext *  context)
protectedvirtual

Registers a new CustomMimeType service object.

This method is called from RegisterService and the default implementation registers a new mime-type service object if all of the following conditions are true:

  • TODO
Parameters
context
Returns
Exceptions
std::invalid_argumentif context is nullptr.

◆ RegisterService()

us::ServiceRegistration<IFileReader> mitk::AbstractFileReader::RegisterService ( us::ModuleContext *  context = us::GetModuleContext())

Associate this reader with the MIME type returned by the current IMimeTypeProvider service for the provided extension if the MIME type exists, otherwise registers a new MIME type when RegisterService() is called.

If no MIME type for extension is already registered, a call to RegisterService() will register a new MIME type and associate this reader instance with it. The MIME type id can be set via SetMimeType() or it will be auto-generated using extension, having the form "application/vnd.mitk.<extension>".

Parameters
context

◆ RemoveProgressCallback()

void mitk::AbstractFileReader::RemoveProgressCallback ( const ProgressCallback callback)
overridevirtual

Implements mitk::IFileIO.

◆ SetDefaultDataNodeProperties()

virtual void mitk::AbstractFileReader::SetDefaultDataNodeProperties ( DataNode node,
const std::string &  filePath 
)
protectedvirtual

◆ SetDefaultOptions()

void mitk::AbstractFileReader::SetDefaultOptions ( const Options defaultOptions)
protected

◆ SetDescription()

void mitk::AbstractFileReader::SetDescription ( const std::string &  description)
protected

◆ SetInput() [1/2]

void mitk::AbstractFileReader::SetInput ( const std::string &  location)
overridevirtual

Set the input location.

Parameters
locationThe file name to read from.

Implements mitk::IFileReader.

◆ SetInput() [2/2]

void mitk::AbstractFileReader::SetInput ( const std::string &  location,
std::istream *  is 
)
overridevirtual

Set an input stream to read from.

Parameters
locationA custom label for the input stream.
isThe input stream.

If is is nullptr, this clears the current input stream and location is interpreted as a file-system path. Otherwise, location is a custom label describing the input stream is.

Implements mitk::IFileReader.

◆ SetMimeType()

void mitk::AbstractFileReader::SetMimeType ( const CustomMimeType mimeType)
protected

◆ SetMimeTypePrefix()

void mitk::AbstractFileReader::SetMimeTypePrefix ( const std::string &  prefix)
protected

◆ SetOption()

void mitk::AbstractFileReader::SetOption ( const std::string &  name,
const us::Any value 
)
overridevirtual

Implements mitk::IFileIO.

◆ SetOptions()

void mitk::AbstractFileReader::SetOptions ( const Options options)
overridevirtual

Implements mitk::IFileIO.

◆ SetProperties()

void mitk::AbstractFileReader::SetProperties ( const PropertyList properties)
overridevirtual

Optionally provide base data properties as a source of meta data.

The purpose of this method is not to preset the base data property list of the read data but to provide access to meta data of previous read operations that may be beneficial for the new read operation.

A typical usecase may occur when reading files from an MITK scene file in which case base data properties are already provided in addition to the actual data file. If such a data file references other files relative to its original location on the filesystem, the original location can be retrieved from the base data properties. In this scenario, GetInputLocation() would return a path within a temporary directory in which the scene file has been extracted. This is not the intended base path for searching referenced external data files.

Implements mitk::IFileReader.

◆ SetRanking()

void mitk::AbstractFileReader::SetRanking ( int  ranking)
protected

Set the service ranking for this file reader.

Default is zero and should only be chosen differently for a reason. The ranking is used to determine which reader to use if several equivalent readers have been found. It may be used to replace a default reader from MITK in your own project. E.g. if you want to use your own reader for nrrd files instead of the default, implement it and give it a higher ranking than zero.

◆ UnregisterService()

void mitk::AbstractFileReader::UnregisterService ( )

Member Data Documentation

◆ m_ReadFiles

std::vector< std::string > mitk::AbstractFileReader::m_ReadFiles
protected

Definition at line 230 of file mitkAbstractFileReader.h.


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