Medical Imaging Interaction Toolkit  2025.12.02
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:
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
#define MITKCORE_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Interface class of writers that write data to files.
virtual std::string GetFileExtension()
Return the extension to be added to the filename.
void SetInput(BaseData *data)
virtual std::string GetPossibleFileExtensionsAsString()
possible file extensions for the data type associated with the writer as string
virtual bool GetWriteToMemory()
virtual const char * GetFilePrefix() const =0
Get the specified file prefix for the file(s) to write.
virtual void ReleaseMemory()
CAUTION: It's up to the user to call this function to release the memory buffer after use in case the...
mitkClassMacroItkParent(FileWriter, itk::ProcessObject)
virtual std::string GetSupportedBaseData() const =0
bool IsExtensionValid(std::string extension)
Checks if given extension is valid for file writer.
virtual bool CanWriteToMemory()
Specifies, whether the file writer also can write a file to a memory buffer.
virtual const char * GetFileName() const =0
Get the specified the file to write.
virtual void SetFileName(const char *aFileName)=0
Specify the file to write.
virtual unsigned int GetMemorySize()
To be used along with a call of SetWriteToMemory(true). This returns the size of the memory buffer wh...
~FileWriter() override
virtual const char * GetMemoryPointer()
To be used along with a call of SetWriteToMemory(true). This returns the memory buffer where the file...
virtual std::vector< std::string > GetPossibleFileExtensions()=0
Return the possible file extensions for the data type associated with the writer.
virtual bool CanWriteDataType(DataNode *)
Check if the Writer can write this type of data of the DataTreenode.
unsigned int m_MemoryBufferSize
virtual void SetWriteToMemory(bool write)
Set/Get functions to advise the file writer to use tis internal memory array as file writing destinat...
virtual std::string GetWritenMIMEType()
Return the MimeType of the saved File.
virtual void SetFilePattern(const char *aFilePattern)=0
Specified file pattern for the file(s) to write. The sprintf format used to build filename from FileP...
virtual void SetFilePrefix(const char *aFilePrefix)=0
Specify file prefix for the file(s) to write.
virtual void Write()=0
virtual const char * GetFilePattern() const =0
Get the specified file pattern for the file(s) to write. The sprintf format used to build filename fr...
Find image slices visible on a given plane.