Medical Imaging Interaction Toolkit  2025.12.02
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 
43  {
44  public:
45  void SetInput(const std::string &location) override;
46 
47  void SetInput(const std::string &location, std::istream *is) override;
48 
49  std::string GetInputLocation() const override;
50 
51  std::istream *GetInputStream() const override;
52 
54 
62  std::vector<itk::SmartPointer<BaseData>> Read() override;
63 
64  DataStorage::SetOfObjects::Pointer Read(mitk::DataStorage &ds) override;
65 
67 
68  Options GetOptions() const override;
69  us::Any GetOption(const std::string &name) const override;
70 
71  void SetOptions(const Options &options) override;
72  void SetOption(const std::string &name, const us::Any &value) override;
73 
74  void AddProgressCallback(const ProgressCallback &callback) override;
75 
76  void RemoveProgressCallback(const ProgressCallback &callback) override;
77 
92 
96  std::vector< std::string > GetReadFiles() override;
97 
98  void SetProperties(const PropertyList* properties) override;
99 
100  protected:
109  class MITKCORE_EXPORT InputStream : public std::istream
110  {
111  public:
112  InputStream(IFileReader *writer, std::ios_base::openmode mode = std::ios_base::in);
113  ~InputStream() override;
114 
115  private:
116  std::istream *m_Stream;
117  };
118 
121 
123 
140  explicit AbstractFileReader(const CustomMimeType &mimeType, const std::string &description);
141 
157  virtual std::vector<itk::SmartPointer<BaseData>> DoRead() = 0;
158 
159 
161 
175  virtual us::ServiceRegistration<CustomMimeType> RegisterMimeType(us::ModuleContext *context);
176 
177  void SetMimeType(const CustomMimeType &mimeType);
178 
182  const CustomMimeType *GetMimeType() const;
183 
184  void SetMimeTypePrefix(const std::string &prefix);
185  std::string GetMimeTypePrefix() const;
186 
187  void SetDescription(const std::string &description);
188  std::string GetDescription() const;
189 
190  void SetDefaultOptions(const Options &defaultOptions);
192 
203  void SetRanking(int ranking);
204  int GetRanking() const;
205 
224  std::string GetLocalFileName() const;
225 
226  virtual void SetDefaultDataNodeProperties(DataNode *node, const std::string &filePath);
227 
228  const PropertyList* GetProperties() const override;
229 
230  std::vector< std::string > m_ReadFiles;
231 
232  private:
233  AbstractFileReader &operator=(const AbstractFileReader &other);
234 
235  virtual mitk::IFileReader *Clone() const = 0;
236 
237  class Impl;
238  std::unique_ptr<Impl> d;
239  };
240 
241 } // namespace mitk
242 
243 #endif
#define MITKCORE_EXPORT
InputStream(IFileReader *writer, std::ios_base::openmode mode=std::ios_base::in)
Base class for creating mitk::BaseData objects from files or streams.
std::vector< std::string > m_ReadFiles
void SetMimeType(const CustomMimeType &mimeType)
AbstractFileReader(const AbstractFileReader &other)
std::vector< std::string > GetReadFiles() override
void SetOption(const std::string &name, const us::Any &value) override
void SetProperties(const PropertyList *properties) override
Optionally provide base data properties as a source of meta data.
ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
std::istream * GetInputStream() const override
Get the input stream.
Options GetOptions() const override
returns a list of the supported options
std::string GetInputLocation() const override
Get the current input location.
void AddProgressCallback(const ProgressCallback &callback) override
MimeType GetRegisteredMimeType() const
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType(us::ModuleContext *context)
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
const PropertyList * GetProperties() const override
virtual us::ServiceProperties GetServiceProperties() const
void SetInput(const std::string &location) override
Set the input location.
const CustomMimeType * GetMimeType() const
void RemoveProgressCallback(const ProgressCallback &callback) override
us::Any GetOption(const std::string &name) const override
std::string GetMimeTypePrefix() const
~AbstractFileReader() override
virtual std::vector< itk::SmartPointer< BaseData > > DoRead()=0
std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
Options GetDefaultOptions() const
virtual void SetDefaultDataNodeProperties(DataNode *node, const std::string &filePath)
void SetMimeTypePrefix(const std::string &prefix)
void SetRanking(int ranking)
Set the service ranking for this file reader.
std::string GetLocalFileName() const
Get a local file name for reading.
AbstractFileReader(const CustomMimeType &mimeType, const std::string &description)
std::string GetDescription() const
void SetDefaultOptions(const Options &defaultOptions)
DataStorage::SetOfObjects::Pointer Read(mitk::DataStorage &ds) override
Reads the specified file or input stream, loading its contents into the provided DataStorage.
void SetOptions(const Options &options) override
void SetDescription(const std::string &description)
void SetInput(const std::string &location, std::istream *is) override
Set an input stream to read from.
The CustomMimeType class represents a custom mime-type which may be registered as a service object....
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Data management class that handles 'was created by' relations.
The MimeType class represents a registered mime-type. It is an immutable wrapper for mitk::CustomMime...
Definition: mitkMimeType.h:37
Key-value list holding instances of BaseProperty.
Definition: usAny.h:164
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
Find image slices visible on a given plane.
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data.
Definition: mitkIFileIO.h:46
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:69
The common interface for all MITK file readers.