ITK  5.1.0
Insight 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:
37  itkTypeMacro(ImageFileWriterException, ExceptionObject);
38 
40  ImageFileWriterException(const char * file,
41  unsigned int line,
42  const char * message = "Error in IO",
43  const char * loc = "Unknown")
44  : ExceptionObject(file, line, message, loc)
45  {}
46 
48  ImageFileWriterException(const std::string & file,
49  unsigned int line,
50  const char * message = "Error in IO",
51  const char * loc = "Unknown")
52  : ExceptionObject(file, line, message, loc)
53  {}
54 
56  ~ImageFileWriterException() noexcept override;
57 };
59 
86 template <typename TInputImage>
87 class ITK_TEMPLATE_EXPORT ImageFileWriter : public ProcessObject
88 {
89 public:
90  ITK_DISALLOW_COPY_AND_ASSIGN(ImageFileWriter);
91 
97 
99  itkNewMacro(Self);
100 
102  itkTypeMacro(ImageFileWriter, ProcessObject);
103 
105  using InputImageType = TInputImage;
106  using InputImagePointer = typename InputImageType::Pointer;
108  using InputImagePixelType = typename InputImageType::PixelType;
109 
111  using Superclass::SetInput;
112  void
113  SetInput(const InputImageType * input);
114 
115  const InputImageType *
116  GetInput();
117 
118  const InputImageType *
119  GetInput(unsigned int idx);
120 
122  itkSetStringMacro(FileName);
123  itkGetStringMacro(FileName);
125 
136  void
138  {
139  if (this->m_ImageIO != io)
140  {
141  this->Modified();
142  this->m_ImageIO = io;
143  }
144  m_FactorySpecifiedImageIO = false;
145  }
146  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
148 
156  virtual void
157  Write();
158 
161  void
162  SetIORegion(const ImageIORegion & region);
163 
164  const ImageIORegion &
165  GetIORegion() const
166  {
167  return m_PasteIORegion;
168  }
169 
172  itkSetMacro(NumberOfStreamDivisions, unsigned int);
173  itkGetConstReferenceMacro(NumberOfStreamDivisions, unsigned int);
175 
178  void
179  Update() override
180  {
181  this->Write();
182  }
183 
189  void
191  {
192  m_PasteIORegion = ImageIORegion(TInputImage::ImageDimension);
193  m_UserSpecifiedIORegion = false;
194  this->Write();
195  }
196 
198  itkSetMacro(UseCompression, bool);
199  itkGetConstReferenceMacro(UseCompression, bool);
200  itkBooleanMacro(UseCompression);
202 
205  itkSetMacro(CompressionLevel, int);
206  itkGetConstReferenceMacro(CompressionLevel, int);
208 
215  itkSetMacro(UseInputMetaDataDictionary, bool);
216  itkGetConstReferenceMacro(UseInputMetaDataDictionary, bool);
217  itkBooleanMacro(UseInputMetaDataDictionary);
219 
220 protected:
221  ImageFileWriter() = default;
222  ~ImageFileWriter() override = default;
223  void
224  PrintSelf(std::ostream & os, Indent indent) const override;
225 
227  void
228  GenerateData() override;
229 
230 private:
231  std::string m_FileName;
232 
234  bool m_UserSpecifiedImageIO{ false };
235 
236  ImageIORegion m_PasteIORegion{ TInputImage::ImageDimension };
237  unsigned int m_NumberOfStreamDivisions{ 1 };
238  bool m_UserSpecifiedIORegion{ false };
239 
240  bool m_FactorySpecifiedImageIO{ false }; // did factory mechanism set the ImageIO?
241  bool m_UseCompression{ false };
242  int m_CompressionLevel{ -1 };
243  bool m_UseInputMetaDataDictionary{ true };
244 };
245 } // end namespace itk
246 
247 #ifndef ITK_MANUAL_INSTANTIATION
248 # include "itkImageFileWriter.hxx"
249 #endif
250 
251 #ifdef ITK_IO_FACTORY_REGISTER_MANAGER
252 # include "itkImageIOFactoryRegisterManager.h"
253 #endif
254 
255 #endif // itkImageFileWriter_h
itk::ImageFileWriter::SetImageIO
void SetImageIO(ImageIOBase *io)
Definition: itkImageFileWriter.h:137
itk::ImageIOBase
Abstract superclass defines image IO interface.
Definition: itkImageIOBase.h:74
itk::ImageFileWriter::m_FileName
std::string m_FileName
Definition: itkImageFileWriter.h:231
itk::ImageFileWriter::Update
void Update() override
Definition: itkImageFileWriter.h:179
itk::ImageFileWriter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkImageFileWriter.h:106
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ImageIORegion
An ImageIORegion represents a structured region of data.
Definition: itkImageIORegion.h:52
itk::ImageFileWriterException::ImageFileWriterException
ImageFileWriterException(const std::string &file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
Definition: itkImageFileWriter.h:48
itk::ImageFileWriter::GetIORegion
const ImageIORegion & GetIORegion() const
Definition: itkImageFileWriter.h:165
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::ImageFileWriter::InputImageType
TInputImage InputImageType
Definition: itkImageFileWriter.h:105
itk::ImageFileWriter
Writes image data to a single file.
Definition: itkImageFileWriter.h:87
itkMacro.h
itk::ImageFileWriter::m_ImageIO
ImageIOBase::Pointer m_ImageIO
Definition: itkImageFileWriter.h:233
itkProcessObject.h
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageFileWriter::InputImagePixelType
typename InputImageType::PixelType InputImagePixelType
Definition: itkImageFileWriter.h:108
itk::ImageFileWriterException::ImageFileWriterException
ImageFileWriterException(const char *file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
Definition: itkImageFileWriter.h:40
itkImageIOBase.h
itk::ImageFileWriterException
Base exception class for IO problems during writing.
Definition: itkImageFileWriter.h:33
itk::ImageFileWriter::UpdateLargestPossibleRegion
void UpdateLargestPossibleRegion() override
Writes the entire image to file.
Definition: itkImageFileWriter.h:190
itk::ImageFileWriter::InputImageRegionType
typename InputImageType::RegionType InputImageRegionType
Definition: itkImageFileWriter.h:107
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:135
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41