Skip to content

Commit

Permalink
ENH: add a convenience function WriteImage
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz authored and hjmjohnson committed Dec 9, 2020
1 parent 7e9934a commit 60b0984
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Modules/IO/ImageBase/include/itkImageFileWriter.h
Expand Up @@ -235,6 +235,63 @@ class ITK_TEMPLATE_EXPORT ImageFileWriter : public ProcessObject
int m_CompressionLevel{ -1 };
bool m_UseInputMetaDataDictionary{ true };
};


/** Convenience function for writing an image. */
template <typename TImage>
ITK_TEMPLATE_EXPORT void
WriteImage(const TImage * image, const char * filename, bool compress = false)
{
using WriterType = ImageFileWriter<TImage>;
typename WriterType::Pointer writer = WriterType::New();
writer->SetInput(image);
writer->SetFileName(filename);
writer->SetUseCompression(compress);
writer->Update();
}
template <typename TImage>
ITK_TEMPLATE_EXPORT void
WriteImage(const SmartPointer<const TImage> image, const char * filename, bool compress = false)
{
WriteImage(image.GetPointer(), filename, compress);
}
template <typename TImage>
ITK_TEMPLATE_EXPORT void
WriteImage(TImage * image, const char * filename, bool compress = false)
{
const TImage * constImage = image;
WriteImage(constImage, filename, compress);
}
template <typename TImage>
ITK_TEMPLATE_EXPORT void
WriteImage(SmartPointer<TImage> image, const char * filename, bool compress = false)
{
WriteImage(image.GetPointer(), filename, compress);
}
template <typename TImage>
ITK_TEMPLATE_EXPORT void
WriteImage(const TImage * image, const std::string & filename, bool compress = false)
{
WriteImage(image, filename.c_str(), compress);
}
template <typename TImage>
ITK_TEMPLATE_EXPORT void
WriteImage(const SmartPointer<const TImage> image, const std::string & filename, bool compress = false)
{
WriteImage(image, filename.c_str(), compress);
}
template <typename TImage>
ITK_TEMPLATE_EXPORT void
WriteImage(TImage * image, const std::string & filename, bool compress = false)
{
WriteImage(image, filename.c_str(), compress);
}
template <typename TImage>
ITK_TEMPLATE_EXPORT void
WriteImage(SmartPointer<TImage> image, const std::string & filename, bool compress = false)
{
WriteImage(image, filename.c_str(), compress);
}
} // end namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
Expand Down

0 comments on commit 60b0984

Please sign in to comment.