00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 00019 #ifndef FILEWRITER_H_HEADER_INCLUDED 00020 #define FILEWRITER_H_HEADER_INCLUDED 00021 00022 #include "mitkCommon.h" 00023 #include <itkProcessObject.h> 00024 #include <mitkDataNode.h> 00025 00026 namespace mitk { 00027 00028 //##Documentation 00029 //## @brief Interface class of writers that write data to files 00030 //## @ingroup Process 00031 class MITK_CORE_EXPORT FileWriter : public itk::ProcessObject 00032 { 00033 public: 00034 mitkClassMacro(FileWriter,itk::ProcessObject); 00035 //##Documentation 00036 //## @brief Get the specified the file to write 00037 //## 00038 //## Either the FileName or FilePrefix plus FilePattern are used to write. 00039 virtual const char* GetFileName() const = 0; 00040 00041 //##Documentation 00042 //## @brief Specify the file to write. 00043 //## 00044 //## Either the FileName or FilePrefix plus FilePattern are used to write. 00045 virtual void SetFileName(const char* aFileName) = 0; 00046 00047 //##Documentation 00048 //## @brief Get the specified file prefix for the file(s) to write. 00049 //## 00050 //## You should specify either a FileName or FilePrefix. Use FilePrefix if 00051 //## the data is stored in multiple files. 00052 virtual const char* GetFilePrefix() const = 0; 00053 00054 //##Documentation 00055 //## @brief Specify file prefix for the file(s) to write. 00056 //## 00057 //## You should specify either a FileName or FilePrefix. Use FilePrefix if 00058 //## the data is stored in multiple files. 00059 virtual void SetFilePrefix(const char* aFilePrefix) = 0; 00060 00061 //##Documentation 00062 //## @brief Get the specified file pattern for the file(s) to write. The 00063 //## sprintf format used to build filename from FilePrefix and number. 00064 //## 00065 //## You should specify either a FileName or FilePrefix. Use FilePrefix if 00066 //## the data is stored in multiple files. 00067 virtual const char* GetFilePattern() const = 0; 00068 00069 //##Documentation 00070 //## @brief Specified file pattern for the file(s) to write. The sprintf 00071 //## format used to build filename from FilePrefix and number. 00072 //## 00073 //## You should specify either a FileName or FilePrefix. Use FilePrefix if 00074 //## the data is stored in multiple files. 00075 virtual void SetFilePattern(const char* aFilePattern) = 0; 00076 00077 //##Documentation 00078 //## @brief Return the extension to be added to the filename. 00079 virtual std::string GetFileExtension(); 00080 00081 //##Documentation 00082 //## @brief Checks if given extension is valid for file writer 00083 bool IsExtensionValid(std::string extension); 00084 00085 //##Documentation 00086 //## @brief Return the possible file extensions for the data type associated with the writer 00087 virtual std::vector<std::string> GetPossibleFileExtensions() = 0; 00088 00089 //##Documentation 00090 //## @brief possible file extensions for the data type associated with the writer as string 00091 virtual std::string GetPossibleFileExtensionsAsString(); 00092 00093 //##Documentation 00094 //## @brief Check if the Writer can write this type of data of the 00095 //## DataTreenode. 00096 virtual bool CanWriteDataType( DataNode* ); 00097 00098 //##Documentation 00099 //## @brief Return the MimeType of the saved File. 00100 virtual std::string GetWritenMIMEType(); 00101 00102 //##Documentation 00103 //## @brief Set the DataTreenode as Input. Important: The Writer 00104 //## always have a SetInput-Function. 00105 virtual void SetInput( DataNode* ); 00106 00107 virtual void Write() = 0; 00108 00109 protected: 00110 00111 FileWriter(); 00112 00113 virtual ~FileWriter(); 00114 00115 }; 00116 00117 #define mitkWriterMacro \ 00118 virtual void Write() \ 00119 { \ 00120 if ( this->GetInput() == NULL ) \ 00121 { \ 00122 itkExceptionMacro(<<"Write:Please specify an input!"); \ 00123 return; \ 00124 } \ 00125 /* Fill in image information.*/ \ 00126 this->UpdateOutputInformation(); \ 00127 (*(this->GetInputs().begin()))->SetRequestedRegionToLargestPossibleRegion();\ 00128 this->PropagateRequestedRegion(NULL); \ 00129 this->UpdateOutputData(NULL); \ 00130 } \ 00131 \ 00132 virtual void Update() \ 00133 { \ 00134 Write(); \ 00135 } 00136 00137 } // namespace mitk 00138 #endif /* FILEWRITER_H_HEADER_INCLUDED */