18#ifndef itkImageFileWriter_h
19#define itkImageFileWriter_h
20#include "ITKIOImageBaseExport.h"
45 const char * message =
"Error in IO",
46 const char * loc =
"Unknown")
47 : ExceptionObject(file, line, message, loc)
53 const char * message =
"Error in IO",
54 const char * loc =
"Unknown")
55 : ExceptionObject(file, line, message, loc)
89template <typename TInputImage>
114 using Superclass::SetInput;
125 itkSetStringMacro(FileName);
126 itkGetStringMacro(FileName);
142 if (this->m_ImageIO != io)
145 this->m_ImageIO = io;
147 m_FactorySpecifiedImageIO =
false;
170 return m_PasteIORegion;
175 itkSetMacro(NumberOfStreamDivisions,
unsigned int);
176 itkGetConstReferenceMacro(NumberOfStreamDivisions,
unsigned int);
195 m_PasteIORegion =
ImageIORegion(TInputImage::ImageDimension);
196 m_UserSpecifiedIORegion =
false;
201 itkSetMacro(UseCompression,
bool);
202 itkGetConstReferenceMacro(UseCompression,
bool);
203 itkBooleanMacro(UseCompression);
208 itkSetMacro(CompressionLevel,
int);
209 itkGetConstReferenceMacro(CompressionLevel,
int);
218 itkSetMacro(UseInputMetaDataDictionary,
bool);
219 itkGetConstReferenceMacro(UseInputMetaDataDictionary,
bool);
220 itkBooleanMacro(UseInputMetaDataDictionary);
234 std::string m_FileName{};
237 bool m_UserSpecifiedImageIO{
false };
240 unsigned int m_NumberOfStreamDivisions{ 1 };
241 bool m_UserSpecifiedIORegion{
false };
243 bool m_FactorySpecifiedImageIO{
false };
244 bool m_UseCompression{
false };
245 int m_CompressionLevel{ -1 };
246 bool m_UseInputMetaDataDictionary{
true };
254template <
typename TImagePo
inter>
255ITK_TEMPLATE_EXPORT
void
256WriteImage(TImagePointer && image,
const std::string & filename,
bool compress =
false)
258 using NonReferenceImagePointer = std::remove_reference_t<TImagePointer>;
259 static_assert(std::is_pointer_v<NonReferenceImagePointer> || mpl::IsSmartPointer<NonReferenceImagePointer>::Value,
260 "WriteImage requires a raw pointer or SmartPointer.");
263 using ImageType = std::remove_const_t<std::remove_reference_t<
decltype(*image)>>;
265 writer->SetInput(image);
266 writer->SetFileName(filename);
267 writer->SetUseCompression(compress);
273#ifndef ITK_MANUAL_INSTANTIATION
274# include "itkImageFileWriter.hxx"
277#if defined ITK_IMAGEIO_FACTORY_REGISTER_MANAGER || defined ITK_IO_FACTORY_REGISTER_MANAGER
278# include "itkImageIOFactoryRegisterManager.h"
Base exception class for IO problems during writing.
~ImageFileWriterException() noexcept override
ImageFileWriterException(const std::string &file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
ImageFileWriterException(const char *file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
ITK_DEFAULT_COPY_AND_MOVE(ImageFileWriterException)
Writes image data to a single file.
void PrintSelf(std::ostream &os, Indent indent) const override
void SetIORegion(const ImageIORegion ®ion)
~ImageFileWriter() override=default
void SetInput(const InputImageType *input)
void SetImageIO(ImageIOBase *io)
void GenerateData() override
typename InputImageType::PixelType InputImagePixelType
TInputImage InputImageType
const InputImageType * GetInput(unsigned int idx)
ImageFileWriter()=default
const ImageIORegion & GetIORegion() const
const InputImageType * GetInput()
typename InputImageType::Pointer InputImagePointer
typename InputImageType::RegionType InputImageRegionType
void UpdateLargestPossibleRegion() override
Writes the entire image to file.
Abstract superclass defines image IO interface.
An ImageIORegion represents a structured region of data.
Control indentation during Print() invocation.
Light weight base class for most itk classes.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
SmartPointer< Self > Pointer
ImageBaseType::RegionType RegionType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT ProcessObject
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)