ITK  4.9.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() throw( );
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();
204  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
205 
207  virtual void GenerateData(void) ITK_OVERRIDE;
208 
209 private:
210  ImageFileWriter(const Self &) ITK_DELETE_FUNCTION;
211  void operator=(const Self &) ITK_DELETE_FUNCTION;
212 
213  std::string m_FileName;
214 
215  ImageIOBase::Pointer m_ImageIO;
216  bool m_UserSpecifiedImageIO; // track whether the ImageIO
217  // is user specified
218 
219  ImageIORegion m_PasteIORegion;
220  unsigned int m_NumberOfStreamDivisions;
221  bool m_UserSpecifiedIORegion; // track whether the region
222  // is user specified
223  bool m_FactorySpecifiedImageIO; //track whether the factory
224  // mechanism set the ImageIO
225  bool m_UseCompression;
226  bool m_UseInputMetaDataDictionary; // whether to use the
227  // MetaDataDictionary from the
228  // input or not.
229 };
230 } // end namespace itk
231 
232 #ifndef ITK_MANUAL_INSTANTIATION
233 #include "itkImageFileWriter.hxx"
234 #endif
235 
236 #ifdef ITK_IO_FACTORY_REGISTER_MANAGER
237 #include "itkImageIOFactoryRegisterManager.h"
238 #endif
239 
240 #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