ITK  4.3.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 
21 #include "itkProcessObject.h"
22 #include "itkImageIOBase.h"
23 #include "itkMacro.h"
24 
25 namespace itk
26 {
32 class ITK_ABI_EXPORT ImageFileWriterException:public ExceptionObject
33 {
34 public:
37 
39  ImageFileWriterException(const char *file, unsigned int line,
40  const char *message = "Error in IO",
41  const char *loc = "Unknown"):
42  ExceptionObject(file, line, message, loc)
43  {}
44 
46  ImageFileWriterException(const std::string & file, unsigned int line,
47  const char *message = "Error in IO",
48  const char *loc = "Unknown"):
49  ExceptionObject(file, line, message, loc)
50  {}
51 
53  virtual ~ImageFileWriterException() throw( )
54  {}
55 };
57 
84 template< class TInputImage >
85 class ITK_EXPORT ImageFileWriter:public ProcessObject
86 {
87 public:
93 
95  itkNewMacro(Self);
96 
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(void);
111 
112  const InputImageType * GetInput(unsigned int idx);
113 
115  itkSetStringMacro(FileName);
116  itkGetStringMacro(FileName);
118 
129  void SetImageIO(ImageIOBase *io)
130  {
131  if ( this->m_ImageIO != io )
132  {
133  this->Modified();
134  this->m_ImageIO = io;
135  }
136  m_FactorySpecifiedImageIO = false;
137  }
139 
140  itkGetObjectMacro(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()
169  {
170  this->Write();
171  }
172 
178  virtual void UpdateLargestPossibleRegion()
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  void PrintSelf(std::ostream & os, Indent indent) const;
206 
208  void GenerateData(void);
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 
217  bool m_UserSpecifiedImageIO; // track whether the ImageIO
218  // is user specified
219 
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
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
242