Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkAbstractFileWriter.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 mitkAbstractFileWriter_h
14 #define mitkAbstractFileWriter_h
15 
16 // Macro
17 #include <MitkCoreExports.h>
18 
19 // MITK
20 #include <mitkIFileWriter.h>
21 #include <mitkMimeType.h>
22 
23 // Microservices
24 #include <usGetModuleContext.h>
25 #include <usServiceProperties.h>
26 #include <usServiceRegistration.h>
27 
28 #include <memory>
29 
30 namespace us
31 {
32  struct PrototypeServiceFactory;
33 }
34 
35 namespace mitk
36 {
37  class CustomMimeType;
38 
51  {
52  public:
53  void SetInput(const BaseData *data) override;
54  const BaseData *GetInput() const override;
55 
56  void SetOutputLocation(const std::string &location) override;
57  std::string GetOutputLocation() const override;
58 
59  void SetOutputStream(const std::string &location, std::ostream *os) override;
60  std::ostream *GetOutputStream() const override;
61 
78  void Write() override = 0;
79 
81 
83 
84  Options GetOptions() const override;
85  us::Any GetOption(const std::string &name) const override;
86 
87  void SetOptions(const Options &options) override;
88  void SetOption(const std::string &name, const us::Any &value) override;
89 
90  void AddProgressCallback(const ProgressCallback &callback) override;
91 
92  void RemoveProgressCallback(const ProgressCallback &callback) override;
93 
96 
97  protected:
107  {
108  public:
110 
111  // Writes to the ostream and removes the temporary file
113 
114  // Creates a temporary file for output operations.
115  std::string GetFileName();
116 
117  private:
118  // disabled
119  LocalFile();
120  LocalFile(const LocalFile &);
121  LocalFile &operator=(const LocalFile &other);
122 
123  struct Impl;
124  std::unique_ptr<Impl> d;
125  };
126 
135  class MITKCORE_EXPORT OutputStream : public std::ostream
136  {
137  public:
138  OutputStream(IFileWriter *writer, std::ios_base::openmode mode = std::ios_base::trunc | std::ios_base::out);
139  ~OutputStream() override;
140 
141  private:
142  std::ostream *m_Stream;
143  };
144 
146 
148 
149  AbstractFileWriter(const std::string &baseDataType);
150 
151  AbstractFileWriter(const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description);
152 
154 
168  virtual us::ServiceRegistration<CustomMimeType> RegisterMimeType(us::ModuleContext *context);
169 
170  void SetMimeType(const CustomMimeType &mimeType);
171 
175  const CustomMimeType *GetMimeType() const;
176 
177  void SetMimeTypePrefix(const std::string &prefix);
178  std::string GetMimeTypePrefix() const;
179 
185  void SetDescription(const std::string &description);
186  std::string GetDescription() const;
187 
188  void SetDefaultOptions(const Options &defaultOptions);
190 
201  void SetRanking(int ranking);
202  int GetRanking() const;
203 
210  void SetBaseDataType(const std::string &baseDataType);
211  virtual std::string GetBaseDataType() const;
212 
214 
215  private:
216  AbstractFileWriter &operator=(const AbstractFileWriter &other);
217 
218  virtual mitk::IFileWriter *Clone() const = 0;
219 
220  class Impl;
221  std::unique_ptr<Impl> d;
222  };
223 
224 } // namespace mitk
225 
226 #endif
#define MITKCORE_EXPORT
A local file representation for streams.
OutputStream(IFileWriter *writer, std::ios_base::openmode mode=std::ios_base::trunc|std::ios_base::out)
Base class for writing mitk::BaseData objects to files or streams.
const BaseData * GetInput() const override
Get the input data set via SetInput().
void SetInput(const BaseData *data) override
Set the input data for writing.
AbstractFileWriter(const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description)
void SetDefaultOptions(const Options &defaultOptions)
Options GetOptions() const override
returns a list of the supported options
void SetOutputStream(const std::string &location, std::ostream *os) override
Set an output stream for writing.
~AbstractFileWriter() override
ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
virtual us::ServiceProperties GetServiceProperties() const
std::string GetOutputLocation() const override
Get the current output location.
void ValidateOutputLocation() const
void AddProgressCallback(const ProgressCallback &callback) override
void SetOutputLocation(const std::string &location) override
Set the output location.
void SetOptions(const Options &options) override
std::string GetDescription() const
virtual std::string GetBaseDataType() const
void SetDescription(const std::string &description)
Sets a human readable description of this writer.
void SetBaseDataType(const std::string &baseDataType)
Sets the name of the mitk::Basedata that this writer is able to handle.
Options GetDefaultOptions() const
us::Any GetOption(const std::string &name) const override
MimeType GetRegisteredMimeType() const
std::string GetMimeTypePrefix() const
void SetMimeTypePrefix(const std::string &prefix)
void Write() override=0
Write the base data to the specified location or output stream.
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType(us::ModuleContext *context)
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
const CustomMimeType * GetMimeType() const
void SetMimeType(const CustomMimeType &mimeType)
void SetOption(const std::string &name, const us::Any &value) override
AbstractFileWriter(const std::string &baseDataType)
void RemoveProgressCallback(const ProgressCallback &callback) override
void SetRanking(int ranking)
Set the service ranking for this file writer.
std::ostream * GetOutputStream() const override
Get the output stream.
AbstractFileWriter(const AbstractFileWriter &other)
Base of all data objects.
Definition: mitkBaseData.h:44
The CustomMimeType class represents a custom mime-type which may be registered as a service object....
The MimeType class represents a registered mime-type. It is an immutable wrapper for mitk::CustomMime...
Definition: mitkMimeType.h:37
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 of all MITK file writers.