Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkAbstractFileReader.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkAbstractFileReader_h
14 #define mitkAbstractFileReader_h
15 
16 // Macro
17 #include <MitkCoreExports.h>
18 
19 // MITK
20 #include <mitkBaseData.h>
21 #include <mitkIFileReader.h>
22 #include <mitkMimeType.h>
23 
24 // Microservices
25 #include <usGetModuleContext.h>
26 #include <usServiceProperties.h>
27 #include <usServiceRegistration.h>
28 
29 namespace us
30 {
32 }
33 
34 namespace mitk
35 {
36  class CustomMimeType;
37 
54  {
55  public:
60  void SetInput(const std::string &location) override;
61 
67  void SetInput(const std::string &location, std::istream *is) override;
68 
73  std::string GetInputLocation() const override;
74 
79  std::istream *GetInputStream() const override;
80 
86 
97  std::vector<itk::SmartPointer<BaseData>> Read() override;
98 
105  DataStorage::SetOfObjects::Pointer Read(mitk::DataStorage &ds) override;
106 
113 
118  Options GetOptions() const override;
119 
125  us::Any GetOption(const std::string &name) const override;
126 
131  void SetOptions(const Options &options) override;
132 
138  void SetOption(const std::string &name, const us::Any &value) override;
139 
144  void AddProgressCallback(const ProgressCallback &callback) override;
145 
150  void RemoveProgressCallback(const ProgressCallback &callback) override;
151 
166 
171 
176  std::vector< std::string > GetReadFiles() override;
177 
183  void SetProperties(const PropertyList* properties) override;
184 
185  protected:
196  class MITKCORE_EXPORT InputStream : public std::istream
197  {
198  public:
205  InputStream(IFileReader *writer, std::ios_base::openmode mode = std::ios_base::in);
206 
207  ~InputStream() override;
208 
209  private:
210  std::istream *m_Stream;
211  };
212 
215 
217 
223 
240  explicit AbstractFileReader(const CustomMimeType &mimeType, const std::string &description);
241 
258  virtual std::vector<itk::SmartPointer<BaseData>> DoRead() = 0;
259 
260 
266 
279 
284  void SetMimeType(const CustomMimeType &mimeType);
285 
290  const CustomMimeType *GetMimeType() const;
291 
296  void SetMimeTypePrefix(const std::string &prefix);
297 
302  std::string GetMimeTypePrefix() const;
303 
308  void SetDescription(const std::string &description);
309 
314  std::string GetDescription() const;
315 
320  void SetDefaultOptions(const Options &defaultOptions);
321 
327 
336  void SetRanking(int ranking);
337 
342  int GetRanking() const;
343 
360  std::string GetLocalFileName() const;
361 
367  virtual void SetDefaultDataNodeProperties(DataNode *node, const std::string &filePath);
368 
373  const PropertyList* GetProperties() const override;
374 
376  std::vector< std::string > m_ReadFiles;
377 
378  private:
379  AbstractFileReader &operator=(const AbstractFileReader &other);
380 
381  virtual mitk::IFileReader *Clone() const = 0;
382 
383  class Impl;
384  std::unique_ptr<Impl> d;
385  };
386 
387 } // namespace mitk
388 
389 #endif
#define MITKCORE_EXPORT
An input stream wrapper for reader implementations.
InputStream(IFileReader *writer, std::ios_base::openmode mode=std::ios_base::in)
Construct an InputStream from a reader's configured input.
Base class for creating mitk::BaseData objects from files or streams.
std::vector< std::string > m_ReadFiles
List of files consumed during the last Read() call. Must be filled by DoRead().
void SetMimeType(const CustomMimeType &mimeType)
Set the MIME type this reader can handle.
AbstractFileReader(const AbstractFileReader &other)
Copy constructor.
std::vector< std::string > GetReadFiles() override
Get the list of files consumed during the last Read() call.
void SetOption(const std::string &name, const us::Any &value) override
Set a single option value.
void SetProperties(const PropertyList *properties) override
Set base data properties as a source of meta data for reading.
ConfidenceLevel GetConfidenceLevel() const override
Determine confidence for reading the current input.
std::istream * GetInputStream() const override
Get the current input stream.
Options GetOptions() const override
Get the current option values.
std::string GetInputLocation() const override
Get the current input location.
void AddProgressCallback(const ProgressCallback &callback) override
Register a progress callback.
MimeType GetRegisteredMimeType() const
Get the mime-type that was registered for this reader.
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType(us::ModuleContext *context)
Register a new CustomMimeType service object.
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Register this reader as a CppMicroServices service.
const PropertyList * GetProperties() const override
Get the properties set via SetProperties().
virtual us::ServiceProperties GetServiceProperties() const
Get the service properties for registration.
void SetInput(const std::string &location) override
Set the input file path, clearing any previously set input stream.
const CustomMimeType * GetMimeType() const
Get the MIME type this reader can handle.
void RemoveProgressCallback(const ProgressCallback &callback) override
Remove a previously registered progress callback.
us::Any GetOption(const std::string &name) const override
Get the value of a specific option.
std::string GetMimeTypePrefix() const
Get the current MIME type name prefix.
~AbstractFileReader() override
virtual std::vector< itk::SmartPointer< BaseData > > DoRead()=0
Perform the actual reading operation.
AbstractFileReader()
Default constructor.
std::vector< itk::SmartPointer< BaseData > > Read() override
Read data and create a list of BaseData objects.
Options GetDefaultOptions() const
Get the default options for this reader.
virtual void SetDefaultDataNodeProperties(DataNode *node, const std::string &filePath)
Set default properties on a DataNode after reading.
void SetMimeTypePrefix(const std::string &prefix)
Set the prefix used for auto-generated MIME type names.
void SetRanking(int ranking)
Set the service ranking for this file reader.
void UnregisterService()
Unregister this reader from the CppMicroServices registry.
std::string GetLocalFileName() const
Get a local file name for reading.
AbstractFileReader(const CustomMimeType &mimeType, const std::string &description)
Associate this reader instance with the given MIME type.
std::string GetDescription() const
Get the human-readable description of this reader.
void SetDefaultOptions(const Options &defaultOptions)
Set the default options for this reader.
DataStorage::SetOfObjects::Pointer Read(mitk::DataStorage &ds) override
Read data and add it to the given DataStorage.
void SetOptions(const Options &options) override
Set multiple options at once.
void SetDescription(const std::string &description)
Set the human-readable description of this reader.
int GetRanking() const
Get the service ranking for this file reader.
void SetInput(const std::string &location, std::istream *is) override
Set an input stream and associated location label.
A custom mime-type that can be registered as a service object.
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
Abstract data management class that organizes DataNode objects in a directed acyclic graph.
Abstract base class for message delegates with one parameter.
Definition: mitkMessage.h:101
Immutable, value-type wrapper for a registered mime-type.
Definition: mitkMimeType.h:45
Key-value list holding instances of BaseProperty.
An Any class represents a general type and is capable of storing any type, supporting type-safe extra...
Definition: usAny.h:145
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
std::unordered_map< std::string, Any > ServiceProperties
Find image slices visible on a given plane.
ConfidenceLevel
A confidence level describing the reader's or writer's ability to handle the given data or file forma...
Definition: mitkIFileIO.h:57
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:80
The common interface for all MITK file readers.
A factory for prototype scope services. The factory can provide multiple, unique service objects.