ITK  5.0.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  ~ImageFileWriterException() noexcept override;
55 };
57 
84 template< typename TInputImage >
85 class ITK_TEMPLATE_EXPORT ImageFileWriter:public ProcessObject
86 {
87 public:
88  ITK_DISALLOW_COPY_AND_ASSIGN(ImageFileWriter);
89 
95 
97  itkNewMacro(Self);
98 
100  itkTypeMacro(ImageFileWriter, ProcessObject);
101 
103  using InputImageType = TInputImage;
104  using InputImagePointer = typename InputImageType::Pointer;
106  using InputImagePixelType = typename InputImageType::PixelType;
107 
109  using Superclass::SetInput;
110  void SetInput(const InputImageType *input);
111 
112  const InputImageType * GetInput();
113 
114  const InputImageType * GetInput(unsigned int idx);
115 
117  itkSetStringMacro(FileName);
118  itkGetStringMacro(FileName);
120 
132  {
133  if ( this->m_ImageIO != io )
134  {
135  this->Modified();
136  this->m_ImageIO = io;
137  }
138  m_FactorySpecifiedImageIO = false;
139  }
140  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
142 
150  virtual void Write();
151 
154  void SetIORegion(const ImageIORegion & region);
155 
156  const ImageIORegion & GetIORegion() const
157  {
158  return m_PasteIORegion;
159  }
160 
163  itkSetMacro(NumberOfStreamDivisions, unsigned int);
164  itkGetConstReferenceMacro(NumberOfStreamDivisions, unsigned int);
166 
169  void Update() override
170  {
171  this->Write();
172  }
173 
180  {
181  m_PasteIORegion = ImageIORegion(TInputImage::ImageDimension);
182  m_UserSpecifiedIORegion = false;
183  this->Write();
184  }
185 
187  itkSetMacro(UseCompression, bool);
188  itkGetConstReferenceMacro(UseCompression, bool);
189  itkBooleanMacro(UseCompression);
191 
198  itkSetMacro(UseInputMetaDataDictionary, bool);
199  itkGetConstReferenceMacro(UseInputMetaDataDictionary, bool);
200  itkBooleanMacro(UseInputMetaDataDictionary);
202 
203 protected:
204  ImageFileWriter();
205  ~ImageFileWriter() override = default;
206  void PrintSelf(std::ostream & os, Indent indent) const override;
207 
209  void GenerateData() override;
210 
211 private:
212  std::string m_FileName;
213 
215  bool m_UserSpecifiedImageIO; // track whether the ImageIO
216  // is user specified
217 
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
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
typename InputImageType::RegionType InputImageRegionType
Light weight base class for most itk classes.
ImageIOBase::Pointer m_ImageIO
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")
typename InputImageType::PixelType InputImagePixelType
ImageIORegion m_PasteIORegion
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
void UpdateLargestPossibleRegion() override
Writes the entire image to file.
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:40
void SetImageIO(ImageIOBase *io)
Base exception class for IO problems during writing.
unsigned int m_NumberOfStreamDivisions
const ImageIORegion & GetIORegion() const
Standard exception handling object.
ImageFileWriterException(const char *file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
Writes image data to a single file.
typename InputImageType::Pointer InputImagePointer
Control indentation during Print() invocation.
Definition: itkIndent.h:49