ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkImageFileWriter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkImageFileWriter_h
19 #define itkImageFileWriter_h
20 #include "ITKIOImageBaseExport.h"
21 
22 #include "itkProcessObject.h"
23 #include "itkImageIOBase.h"
24 #include "itkMacro.h"
25 
26 namespace itk
27 {
33 class ITKIOImageBase_EXPORT ImageFileWriterException:public ExceptionObject
34 {
35 public:
38 
40  ImageFileWriterException(const char *file, unsigned int line,
41  const char *message = "Error in IO",
42  const char *loc = "Unknown"):
43  ExceptionObject(file, line, message, loc)
44  {}
45 
47  ImageFileWriterException(const std::string & file, unsigned int line,
48  const char *message = "Error in IO",
49  const char *loc = "Unknown"):
50  ExceptionObject(file, line, message, loc)
51  {}
52 
54  virtual ~ImageFileWriterException() ITK_NOEXCEPT ITK_OVERRIDE;
55 };
57 
84 template< typename TInputImage >
85 class ITKIOImageBase_HIDDEN ImageFileWriter:public ProcessObject
86 {
87 public:
90  typedef ProcessObject Superclass;
93 
95  itkNewMacro(Self);
96 
98  itkTypeMacro(ImageFileWriter, ProcessObject);
99 
101  typedef TInputImage InputImageType;
102  typedef typename InputImageType::Pointer InputImagePointer;
103  typedef typename InputImageType::RegionType InputImageRegionType;
104  typedef typename InputImageType::PixelType InputImagePixelType;
105 
107  using Superclass::SetInput;
108  void SetInput(const InputImageType *input);
109 
110  const InputImageType * GetInput();
111 
112  const InputImageType * GetInput(unsigned int idx);
113 
115  itkSetStringMacro(FileName);
116  itkGetStringMacro(FileName);
118 
130  {
131  if ( this->m_ImageIO != io )
132  {
133  this->Modified();
134  this->m_ImageIO = io;
135  }
136  m_FactorySpecifiedImageIO = false;
137  }
138  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
140 
148  virtual void Write();
149 
152  void SetIORegion(const ImageIORegion & region);
153 
154  const ImageIORegion & GetIORegion(void) const
155  {
156  return m_PasteIORegion;
157  }
158 
161  itkSetMacro(NumberOfStreamDivisions, unsigned int);
162  itkGetConstReferenceMacro(NumberOfStreamDivisions, unsigned int);
164 
167  virtual void Update() ITK_OVERRIDE
168  {
169  this->Write();
170  }
171 
177  virtual void UpdateLargestPossibleRegion() ITK_OVERRIDE
178  {
179  m_PasteIORegion = ImageIORegion(TInputImage::ImageDimension);
180  m_UserSpecifiedIORegion = false;
181  this->Write();
182  }
183 
185  itkSetMacro(UseCompression, bool);
186  itkGetConstReferenceMacro(UseCompression, bool);
187  itkBooleanMacro(UseCompression);
189 
196  itkSetMacro(UseInputMetaDataDictionary, bool);
197  itkGetConstReferenceMacro(UseInputMetaDataDictionary, bool);
198  itkBooleanMacro(UseInputMetaDataDictionary);
200 
201 protected:
202  ImageFileWriter();
203  ~ImageFileWriter() ITK_OVERRIDE;
204  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
205 
207  virtual void GenerateData(void) ITK_OVERRIDE;
208 
209 private:
210  ITK_DISALLOW_COPY_AND_ASSIGN(ImageFileWriter);
211 
212  std::string m_FileName;
213 
214  ImageIOBase::Pointer m_ImageIO;
215  bool m_UserSpecifiedImageIO; // track whether the ImageIO
216  // is user specified
217 
218  ImageIORegion m_PasteIORegion;
219  unsigned int m_NumberOfStreamDivisions;
220  bool m_UserSpecifiedIORegion; // track whether the region
221  // is user specified
222  bool m_FactorySpecifiedImageIO; //track whether the factory
223  // mechanism set the ImageIO
224  bool m_UseCompression;
225  bool m_UseInputMetaDataDictionary; // whether to use the
226  // MetaDataDictionary from the
227  // input or not.
228 };
229 } // end namespace itk
230 
231 #ifndef ITK_MANUAL_INSTANTIATION
232 #include "itkImageFileWriter.hxx"
233 #endif
234 
235 #ifdef ITK_IO_FACTORY_REGISTER_MANAGER
236 #include "itkImageIOFactoryRegisterManager.h"
237 #endif
238 
239 #endif // itkImageFileWriter_h
SmartPointer< Self > Pointer
An ImageIORegion represents a structured region of data.
Abstract superclass defines image IO interface.
ImageFileWriterException(const std::string &file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
InputImageType::PixelType InputImagePixelType
const ImageIORegion & GetIORegion(void) const
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
void SetImageIO(ImageIOBase *io)
InputImageType::Pointer InputImagePointer
Base exception class for IO problems during writing.
virtual void UpdateLargestPossibleRegion() override
Writes the entire image to file.
SmartPointer< const Self > ConstPointer
InputImageType::RegionType InputImageRegionType
Standard exception handling object.
ImageFileWriterException(const char *file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
virtual void Update() override
Writes image data to a single file.
Control indentation during Print() invocation.
Definition: itkIndent.h:49