Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
Medical Imaging Interaction Toolkit
mitkFileWriter.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 mitkFileWriter_h
14 #define mitkFileWriter_h
15 
16 #include <MitkCoreExports.h>
17 #include <itkProcessObject.h>
18 #include <mitkDataNode.h>
19 
20 namespace mitk
21 {
22  //##Documentation
23  //## @brief Interface class of writers that write data to files
24  //## @ingroup DeprecatedIO
25  //## @deprecatedSince{2014_10} Use mitk::IFileWriter instead.
26  class MITKCORE_EXPORT FileWriter : public itk::ProcessObject
27  {
28  public:
29  mitkClassMacroItkParent(FileWriter, itk::ProcessObject);
30  //##Documentation
31  //## @brief Get the specified the file to write
32  //##
33  //## Either the FileName or FilePrefix plus FilePattern are used to write.
34  virtual const char *GetFileName() const = 0;
35 
36  //##Documentation
37  //## @brief Specify the file to write.
38  //##
39  //## Either the FileName or FilePrefix plus FilePattern are used to write.
40  virtual void SetFileName(const char *aFileName) = 0;
41 
42  //##Documentation
43  //## @brief Get the specified file prefix for the file(s) to write.
44  //##
45  //## You should specify either a FileName or FilePrefix. Use FilePrefix if
46  //## the data is stored in multiple files.
47  virtual const char *GetFilePrefix() const = 0;
48 
49  //##Documentation
50  //## @brief Specify file prefix for the file(s) to write.
51  //##
52  //## You should specify either a FileName or FilePrefix. Use FilePrefix if
53  //## the data is stored in multiple files.
54  virtual void SetFilePrefix(const char *aFilePrefix) = 0;
55 
56  //##Documentation
57  //## @brief Get the specified file pattern for the file(s) to write. The
58  //## sprintf format used to build filename from FilePrefix and number.
59  //##
60  //## You should specify either a FileName or FilePrefix. Use FilePrefix if
61  //## the data is stored in multiple files.
62  virtual const char *GetFilePattern() const = 0;
63 
64  //##Documentation
65  //## @brief Specified file pattern for the file(s) to write. The sprintf
66  //## format used to build filename from FilePrefix and number.
67  //##
68  //## You should specify either a FileName or FilePrefix. Use FilePrefix if
69  //## the data is stored in multiple files.
70  virtual void SetFilePattern(const char *aFilePattern) = 0;
71 
72  //##Documentation
73  //## @brief Return the extension to be added to the filename.
74  virtual std::string GetFileExtension();
75 
76  //##Documentation
77  //## @brief Checks if given extension is valid for file writer
78  bool IsExtensionValid(std::string extension);
79 
80  //##Documentation
81  //## @brief Return the possible file extensions for the data type associated with the writer
82  virtual std::vector<std::string> GetPossibleFileExtensions() = 0;
83 
84  //##Documentation
85  //## @brief possible file extensions for the data type associated with the writer as string
86  virtual std::string GetPossibleFileExtensionsAsString();
87 
88  //##Documentation
89  //## @brief Check if the Writer can write this type of data of the
90  //## DataTreenode.
91  virtual bool CanWriteDataType(DataNode *);
92 
93  //##Documentation
94  //## @brief Return the MimeType of the saved File.
95  virtual std::string GetWritenMIMEType();
96 
97  virtual std::string GetSupportedBaseData() const = 0;
98 
99  using ProcessObject::SetInput;
100  void SetInput(BaseData *data);
101 
102  virtual void Write() = 0;
103 
107  virtual bool CanWriteToMemory();
108 
112  virtual void SetWriteToMemory(bool write);
113  virtual bool GetWriteToMemory();
114 
118  virtual const char *GetMemoryPointer();
119 
123  virtual unsigned int GetMemorySize();
124 
128  virtual void ReleaseMemory();
129 
130  protected:
131  FileWriter();
132  ~FileWriter() override;
133 
137  unsigned int m_MemoryBufferSize;
138  };
139 
140 #define mitkWriterMacro \
141  \
142  virtual void Write() override \
143  \
144  { \
145  if (this->GetInput() == nullptr) \
146  \
147  { \
148  itkExceptionMacro(<< "Write:Please specify an input!"); \
149  return; \
150  } \
151  /* Fill in image information.*/ \
152  this->UpdateOutputInformation(); \
153  (*(this->GetInputs().begin()))->SetRequestedRegionToLargestPossibleRegion(); \
154  this->PropagateRequestedRegion(nullptr); \
155  this->UpdateOutputData(nullptr); \
156  } \
157  \
158  virtual void Update() override { Write(); }
159 } // namespace mitk
160 #endif
mitk::FileWriter
Interface class of writers that write data to files.
Definition: mitkFileWriter.h:26
mitkClassMacroItkParent
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:45
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::FileWriter::m_MemoryBufferSize
unsigned int m_MemoryBufferSize
Definition: mitkFileWriter.h:137
MitkCoreExports.h
mitk::FileWriter::m_CanWriteToMemory
bool m_CanWriteToMemory
Definition: mitkFileWriter.h:134
mitk::FileWriter::m_WriteToMemory
bool m_WriteToMemory
Definition: mitkFileWriter.h:135
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitkDataNode.h
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::FileWriter::m_MemoryBuffer
char * m_MemoryBuffer
Definition: mitkFileWriter.h:136
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63