go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkImageFileCastWriter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright UMC Utrecht and contributors
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 itkImageFileCastWriter_h
19#define itkImageFileCastWriter_h
20
21#include "itkImageFileWriter.h"
22#include "itkImageIOBase.h"
23#include "itkMacro.h"
24#include "itkSize.h"
25#include "itkImageIORegion.h"
26#include "itkCastImageFilter.h"
27#include "elxDefaultConstruct.h"
28
29namespace itk
30{
31
40template <class TInputImage>
41class ITK_TEMPLATE_EXPORT ImageFileCastWriter : public ImageFileWriter<TInputImage>
42{
43public:
45
49 using Pointer = SmartPointer<Self>;
50 using ConstPointer = SmartPointer<const Self>;
51
53 itkNewMacro(Self);
54
57
59 using typename Superclass::InputImageType;
60 using typename Superclass::InputImagePointer;
61 using typename Superclass::InputImageRegionType;
62 using typename Superclass::InputImagePixelType;
63
64 itkStaticConstMacro(InputImageDimension, unsigned int, InputImageType::ImageDimension);
65
69 itkSetStringMacro(OutputComponentType);
70 itkGetStringMacro(OutputComponentType);
71
72protected:
74 ~ImageFileCastWriter() override = default;
75
77 void
78 GenerateData() override;
79
80private:
82 static std::string
84
89 template <class OutputComponentType>
90 void *
91 ConvertScalarImage(const DataObject * inputImage)
92 {
94 using InputImageComponentType = typename PixelTraits<InputImagePixelType>::ValueType;
95 using ScalarInputImageType = Image<InputImageComponentType, InputImageDimension>;
96
98 this->GetModifiableImageIO()->SetPixelTypeInfo(static_cast<const OutputComponentType *>(nullptr));
99
101 const auto caster = CastImageFilter<ScalarInputImageType, DiskImageType>::New();
102 this->m_Caster = caster;
103 const auto localInputImage = ScalarInputImageType::New();
104
105 localInputImage->Graft(static_cast<const ScalarInputImageType *>(inputImage));
106
107 caster->SetInput(localInputImage);
108 caster->Update();
109
111 return caster->GetOutput()->GetBufferPointer();
112 }
113
114
115 ProcessObject::Pointer m_Caster{ nullptr };
116
117 std::string m_OutputComponentType{ Self::GetDefaultOutputComponentType() };
118};
119
121template <typename TImage>
122void
123WriteCastedImage(const TImage & image,
124 const std::string & filename,
125 const std::string & outputComponentType,
126 bool compress)
127{
129 writer.SetInput(&image);
130 writer.SetFileName(filename);
131 writer.SetOutputComponentType(outputComponentType);
132 writer.SetUseCompression(compress);
133 writer.Update();
134}
135
136} // end namespace itk
137
138#ifndef ITK_MANUAL_INSTANTIATION
139# include "itkImageFileCastWriter.hxx"
140#endif
141
142#endif // itkImageFileCastWriter_h
Casts pixel type and writes image data.
itkStaticConstMacro(InputImageDimension, unsigned int, InputImageType::ImageDimension)
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)


Generated on 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo