18#ifndef itkImageFileCastWriter_h
19#define itkImageFileCastWriter_h
21#include "itkImageFileWriter.h"
22#include "itkImageIOBase.h"
25#include "itkImageIORegion.h"
26#include "itkCastImageFilter.h"
40template <
class TInputImage>
59 using typename Superclass::InputImageType;
60 using typename Superclass::InputImagePointer;
61 using typename Superclass::InputImageRegionType;
62 using typename Superclass::InputImagePixelType;
69 itkSetStringMacro(OutputComponentType);
70 itkGetStringMacro(OutputComponentType);
89 template <
class OutputComponentType>
94 using InputImageComponentType =
typename PixelTraits<InputImagePixelType>::ValueType;
98 this->GetModifiableImageIO()->SetPixelTypeInfo(
static_cast<const OutputComponentType *
>(
nullptr));
101 const auto caster = CastImageFilter<ScalarInputImageType, DiskImageType>::New();
102 this->m_Caster = caster;
103 const auto localInputImage = ScalarInputImageType::New();
105 localInputImage->Graft(
static_cast<const ScalarInputImageType *
>(inputImage));
107 caster->SetInput(localInputImage);
111 return caster->GetOutput()->GetBufferPointer();
115 ProcessObject::Pointer m_Caster{
nullptr };
117 std::string m_OutputComponentType{ Self::GetDefaultOutputComponentType() };
121template <
typename TImage>
124 const std::string & filename,
125 const std::string & outputComponentType,
129 writer.SetInput(&image);
130 writer.SetFileName(filename);
131 writer.SetOutputComponentType(outputComponentType);
132 writer.SetUseCompression(compress);
138#ifndef ITK_MANUAL_INSTANTIATION
139# include "itkImageFileCastWriter.hxx"
Casts pixel type and writes image data.
itkStaticConstMacro(InputImageDimension, unsigned int, InputImageType::ImageDimension)
ImageFileCastWriter()=default
ITK_DISALLOW_COPY_AND_MOVE(ImageFileCastWriter)
~ImageFileCastWriter() override=default
SmartPointer< const Self > ConstPointer
void GenerateData() override
void * ConvertScalarImage(const DataObject *inputImage)
static std::string GetDefaultOutputComponentType()
void WriteCastedImage(const TImage &image, const std::string &filename, const std::string &outputComponentType, bool compress)