Medical Imaging Interaction Toolkit  2024.06.00
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 
80  ConfidenceLevel GetConfidenceLevel() const override;
81 
82  MimeType GetRegisteredMimeType() const;
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 
94  us::ServiceRegistration<IFileWriter> RegisterService(us::ModuleContext *context = us::GetModuleContext());
95  void UnregisterService();
96 
97  protected:
107  {
108  public:
109  LocalFile(IFileWriter *writer);
110 
111  // Writes to the ostream and removes the temporary file
112  ~LocalFile();
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 
145  ~AbstractFileWriter() override;
146 
148 
149  AbstractFileWriter(const std::string &baseDataType);
150 
151  AbstractFileWriter(const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description);
152 
153  virtual us::ServiceProperties GetServiceProperties() const;
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);
189  Options GetDefaultOptions() const;
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 
213  void ValidateOutputLocation() const;
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
us::ServiceProperties
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
Definition: usServiceProperties.h:42
usServiceProperties.h
mitk::IFileIO::Options
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:69
us
Definition: mitkAbstractFileReader.h:29
mitk::CustomMimeType
The CustomMimeType class represents a custom mime-type which may be registered as a service object....
Definition: mitkCustomMimeType.h:44
us::GetModuleContext
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
Definition: usGetModuleContext.h:50
mitk::AbstractFileWriter::OutputStream
An output stream wrapper.
Definition: mitkAbstractFileWriter.h:135
mitkMimeType.h
mitk::AbstractFileWriter
Base class for writing mitk::BaseData objects to files or streams.
Definition: mitkAbstractFileWriter.h:50
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::IFileWriter
The common interface of all MITK file writers.
Definition: mitkIFileWriter.h:56
mitkIFileWriter.h
mitk::AbstractFileWriter::LocalFile
A local file representation for streams.
Definition: mitkAbstractFileWriter.h:106
us::Any
Definition: usAny.h:163
MitkCoreExports.h
mitk::MessageAbstractDelegate1
Definition: mitkMessage.h:93
usServiceRegistration.h
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
usGetModuleContext.h
mitk::IFileIO::ConfidenceLevel
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data.
Definition: mitkIFileIO.h:45
us::ServiceRegistration
Definition: usServiceRegistration.h:48
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::MimeType
The MimeType class represents a registered mime-type. It is an immutable wrapper for mitk::CustomMime...
Definition: mitkMimeType.h:36