ITK  4.4.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  }
138  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
140 
148  virtual void Write(void);
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()
168  {
169  this->Write();
170  }
171 
177  virtual void UpdateLargestPossibleRegion()
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  void PrintSelf(std::ostream & os, Indent indent) const;
205 
207  void GenerateData(void);
208 
209 private:
210  ImageFileWriter(const Self &); //purposely not implemented
211  void operator=(const Self &); //purposely not implemented
212 
213  std::string m_FileName;
214 
216  bool m_UserSpecifiedImageIO; // track whether the ImageIO
217  // is user specified
218 
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
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
241