Loading...
Searching...
No Matches
itkImageFileCastWriter.h
Go to the documentation of this file.
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkImageFileCastWriter_h
#define itkImageFileCastWriter_h
#include "itkImageFileWriter.h"
#include "itkImageIOBase.h"
#include "itkMacro.h"
#include "itkSize.h"
#include "itkImageIORegion.h"
#include "itkCastImageFilter.h"
#include "elxDefaultConstruct.h"
namespace itk
{
template <class TInputImage>
class ITK_TEMPLATE_EXPORT ImageFileCastWriter : public ImageFileWriter<TInputImage>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(ImageFileCastWriter);
using Self = ImageFileCastWriter;
using Superclass = ImageFileWriter<TInputImage>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
itkNewMacro(Self);
itkTypeMacro(ImageFileCastWriter, ImageFileWriter);
using typename Superclass::InputImageType;
using typename Superclass::InputImagePointer;
using typename Superclass::InputImageRegionType;
using typename Superclass::InputImagePixelType;
itkStaticConstMacro(InputImageDimension, unsigned int, InputImageType::ImageDimension);
itkSetStringMacro(OutputComponentType);
itkGetStringMacro(OutputComponentType);
protected:
ImageFileCastWriter() = default;
~ImageFileCastWriter() override = default;
void
GenerateData() override;
private:
static std::string
GetDefaultOutputComponentType();
template <class OutputComponentType>
void *
ConvertScalarImage(const DataObject * inputImage)
{
using DiskImageType = Image<OutputComponentType, InputImageDimension>;
using InputImageComponentType = typename PixelTraits<InputImagePixelType>::ValueType;
using ScalarInputImageType = Image<InputImageComponentType, InputImageDimension>;
this->GetModifiableImageIO()->SetPixelTypeInfo(static_cast<const OutputComponentType *>(nullptr));
const auto caster = CastImageFilter<ScalarInputImageType, DiskImageType>::New();
this->m_Caster = caster;
const auto localInputImage = ScalarInputImageType::New();
localInputImage->Graft(static_cast<const ScalarInputImageType *>(inputImage));
caster->SetInput(localInputImage);
caster->Update();
return caster->GetOutput()->GetBufferPointer();
}
ProcessObject::Pointer m_Caster{ nullptr };
std::string m_OutputComponentType{ Self::GetDefaultOutputComponentType() };
};
template <typename TImage>
void
WriteCastedImage(const TImage & image,
const std::string & filename,
const std::string & outputComponentType,
bool compress)
{
elx::DefaultConstruct<ImageFileCastWriter<TImage>> writer;
writer.SetInput(&image);
writer.SetFileName(filename);
writer.SetOutputComponentType(outputComponentType);
writer.SetUseCompression(compress);
writer.Update();
}
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
# include "itkImageFileCastWriter.hxx"
#endif
#endif // itkImageFileCastWriter_h
ImageFileWriter
elastix::DefaultConstruct
Definition elxDefaultConstruct.h:36
itk::ImageFileCastWriter::itkStaticConstMacro
itkStaticConstMacro(InputImageDimension, unsigned int, InputImageType::ImageDimension)
itk::ImageFileCastWriter::ImageFileCastWriter
ImageFileCastWriter()=default
itk::ImageFileCastWriter::m_OutputComponentType
std::string m_OutputComponentType
Definition itkImageFileCastWriter.h:117
itk::ImageFileCastWriter::ITK_DISALLOW_COPY_AND_MOVE
ITK_DISALLOW_COPY_AND_MOVE(ImageFileCastWriter)
itk::ImageFileCastWriter::Superclass
ImageFileWriter< TInputImage > Superclass
Definition itkImageFileCastWriter.h:48
itk::ImageFileCastWriter::m_Caster
ProcessObject::Pointer m_Caster
Definition itkImageFileCastWriter.h:115
itk::ImageFileCastWriter::~ImageFileCastWriter
~ImageFileCastWriter() override=default
itk::ImageFileCastWriter::Pointer
SmartPointer< Self > Pointer
Definition itkImageFileCastWriter.h:49
itk::ImageFileCastWriter::ConstPointer
SmartPointer< const Self > ConstPointer
Definition itkImageFileCastWriter.h:50
itk::ImageFileCastWriter::GenerateData
void GenerateData() override
itk::ImageFileCastWriter::ConvertScalarImage
void * ConvertScalarImage(const DataObject *inputImage)
Definition itkImageFileCastWriter.h:91
itk::ImageFileCastWriter::Self
ImageFileCastWriter Self
Definition itkImageFileCastWriter.h:47
itk::ImageFileCastWriter::GetDefaultOutputComponentType
static std::string GetDefaultOutputComponentType()
elxDefaultConstruct.h
itk
Definition itkAdvancedImageToImageMetric.h:43
itk::WriteCastedImage
void WriteCastedImage(const TImage &image, const std::string &filename, const std::string &outputComponentType, bool compress)
Definition itkImageFileCastWriter.h:123

Generated on 1768596610 for elastix by 1.15.0 |