ITK  4.6.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 ITK_ABI_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  {}
56 };
58 
85 template< typename TInputImage >
86 class ITKIOImageBase_HIDDEN ImageFileWriter:public ProcessObject
87 {
88 public:
94 
96  itkNewMacro(Self);
97 
100 
102  typedef TInputImage InputImageType;
103  typedef typename InputImageType::Pointer InputImagePointer;
104  typedef typename InputImageType::RegionType InputImageRegionType;
105  typedef typename InputImageType::PixelType InputImagePixelType;
106 
108  using Superclass::SetInput;
109  void SetInput(const InputImageType *input);
110 
111  const InputImageType * GetInput(void);
112 
113  const InputImageType * GetInput(unsigned int idx);
114 
116  itkSetStringMacro(FileName);
117  itkGetStringMacro(FileName);
119 
131  {
132  if ( this->m_ImageIO != io )
133  {
134  this->Modified();
135  this->m_ImageIO = io;
136  }
137  m_FactorySpecifiedImageIO = false;
138  }
139  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
141 
149  virtual void Write(void);
150 
153  void SetIORegion(const ImageIORegion & region);
154 
155  const ImageIORegion & GetIORegion(void) const
156  {
157  return m_PasteIORegion;
158  }
159 
162  itkSetMacro(NumberOfStreamDivisions, unsigned int);
163  itkGetConstReferenceMacro(NumberOfStreamDivisions, unsigned int);
165 
168  virtual void Update() ITK_OVERRIDE
169  {
170  this->Write();
171  }
172 
178  virtual void UpdateLargestPossibleRegion() ITK_OVERRIDE
179  {
180  m_PasteIORegion = ImageIORegion(TInputImage::ImageDimension);
181  m_UserSpecifiedIORegion = false;
182  this->Write();
183  }
184 
186  itkSetMacro(UseCompression, bool);
187  itkGetConstReferenceMacro(UseCompression, bool);
188  itkBooleanMacro(UseCompression);
190 
197  itkSetMacro(UseInputMetaDataDictionary, bool);
198  itkGetConstReferenceMacro(UseInputMetaDataDictionary, bool);
199  itkBooleanMacro(UseInputMetaDataDictionary);
201 
202 protected:
203  ImageFileWriter();
204  ~ImageFileWriter();
205  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
206 
208  virtual void GenerateData(void) ITK_OVERRIDE;
209 
210 private:
211  ImageFileWriter(const Self &); //purposely not implemented
212  void operator=(const Self &); //purposely not implemented
213 
214  std::string m_FileName;
215 
216  ImageIOBase::Pointer m_ImageIO;
217  bool m_UserSpecifiedImageIO; // track whether the ImageIO
218  // is user specified
219 
220  ImageIORegion m_PasteIORegion;
221  unsigned int m_NumberOfStreamDivisions;
222  bool m_UserSpecifiedIORegion; // track whether the region
223  // is user specified
224  bool m_FactorySpecifiedImageIO; //track whether the factory
225  // mechanism set the ImageIO
226  bool m_UseCompression;
227  bool m_UseInputMetaDataDictionary; // whether to use the
228  // MetaDataDictionary from the
229  // input or not.
230 };
231 } // end namespace itk
232 
233 #ifndef ITK_MANUAL_INSTANTIATION
234 #include "itkImageFileWriter.hxx"
235 #endif
236 
237 #ifdef ITK_IO_FACTORY_REGISTER_MANAGER
238 #include "itkImageIOFactoryRegisterManager.h"
239 #endif
240 
241 #endif // __itkImageFileWriter_h
Light weight base class for most itk classes.
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.
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() ITK_OVERRIDE
Writes image data to a single file.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void UpdateLargestPossibleRegion() ITK_OVERRIDE
Writes the entire image to file.