13 #ifndef __itkCastImageFileWriter_hxx 14 #define __itkCastImageFileWriter_hxx 16 #include "itkImageFileWriter.h" 17 #include "itkDataObject.h" 18 #include "itkObjectFactoryBase.h" 19 #include "itkImageIOFactory.h" 20 #include "itkCommand.h" 22 #include "itkCastImageFilter.h" 28 template <
class TInputImage>
31 m_PasteIORegion(TInputImage::ImageDimension)
33 m_UseCompression =
false;
34 m_UseInputMetaDataDictionary =
true;
35 m_FactorySpecifiedImageIO =
false;
36 m_UserSpecifiedIORegion =
false;
37 m_UserSpecifiedImageIO =
false;
38 m_NumberOfStreamDivisions = 1;
39 m_ComponentType = ImageIOBase::DOUBLE;
43 template <
class TInputImage>
50 template <
class TInputImage>
56 this->ProcessObject::SetNthInput(0,
57 const_cast<TInputImage *>(input ) );
62 template <
class TInputImage>
67 if (this->GetNumberOfInputs() < 1)
72 return static_cast<TInputImage*
> 73 (this->ProcessObject::GetInput(0));
77 template <
class TInputImage>
82 return static_cast<TInputImage*
> (this->ProcessObject::GetInput(idx));
86 template <
class TInputImage>
91 itkDebugMacro(
"setting IORegion to " << region );
92 if ( m_PasteIORegion != region)
94 m_PasteIORegion = region;
96 m_UserSpecifiedIORegion =
true;
101 template <
class TInputImage>
106 itkDebugMacro( <<
"Writing an image file" );
107 this->GenerateData();
112 template <
class TInputImage>
119 itkDebugMacro(<<
"Writing file: " << m_FileName);
124 typedef Image<unsigned char, TInputImage::ImageDimension> UCharImageType;
125 typedef Image<char, TInputImage::ImageDimension> CharImageType;
126 typedef Image<unsigned short, TInputImage::ImageDimension> UShortImageType;
127 typedef Image<short, TInputImage::ImageDimension> ShortImageType;
128 typedef Image<unsigned int, TInputImage::ImageDimension> UIntImageType;
129 typedef Image<int, TInputImage::ImageDimension> IntImageType;
130 typedef Image<unsigned long, TInputImage::ImageDimension> ULongImageType;
131 typedef Image<long, TInputImage::ImageDimension> LongImageType;
132 typedef Image<float, TInputImage::ImageDimension> FloatImageType;
133 typedef Image<double, TInputImage::ImageDimension> DoubleImageType;
135 typedef ImageFileWriter<UCharImageType> UCharWriterType;
136 typedef ImageFileWriter<CharImageType> CharWriterType;
137 typedef ImageFileWriter<UShortImageType> UShortWriterType;
138 typedef ImageFileWriter<ShortImageType> ShortWriterType;
139 typedef ImageFileWriter<UIntImageType> UIntWriterType;
140 typedef ImageFileWriter<IntImageType> IntWriterType;
141 typedef ImageFileWriter<ULongImageType> ULongWriterType;
142 typedef ImageFileWriter<LongImageType> LongWriterType;
143 typedef ImageFileWriter<FloatImageType> FloatWriterType;
144 typedef ImageFileWriter<DoubleImageType> DoubleWriterType;
146 typedef CastImageFilter<TInputImage, UCharImageType> UCharCastFilterType;
147 typedef CastImageFilter<TInputImage, CharImageType> CharCastFilterType;
148 typedef CastImageFilter<TInputImage, UShortImageType> UShortCastFilterType;
149 typedef CastImageFilter<TInputImage, ShortImageType> ShortCastFilterType;
150 typedef CastImageFilter<TInputImage, UIntImageType> UIntCastFilterType;
151 typedef CastImageFilter<TInputImage, IntImageType> IntCastFilterType;
152 typedef CastImageFilter<TInputImage, ULongImageType> ULongCastFilterType;
153 typedef CastImageFilter<TInputImage, LongImageType> LongCastFilterType;
154 typedef CastImageFilter<TInputImage, FloatImageType> FloatCastFilterType;
155 typedef CastImageFilter<TInputImage, DoubleImageType> DoubleCastFilterType;
157 typename UCharWriterType::Pointer ucharWriter;
158 typename CharWriterType::Pointer charWriter;
159 typename UShortWriterType::Pointer ushortWriter;
160 typename ShortWriterType::Pointer shortWriter;
161 typename UIntWriterType::Pointer uintWriter;
162 typename IntWriterType::Pointer intWriter;
163 typename ULongWriterType::Pointer ulongWriter;
164 typename LongWriterType::Pointer longWriter;
165 typename FloatWriterType::Pointer floatWriter;
166 typename DoubleWriterType::Pointer doubleWriter;
168 typename UCharCastFilterType::Pointer ucharCastFilter;
169 typename CharCastFilterType::Pointer charCastFilter;
170 typename UShortCastFilterType::Pointer ushortCastFilter;
171 typename ShortCastFilterType::Pointer shortCastFilter;
172 typename UIntCastFilterType::Pointer uintCastFilter;
173 typename IntCastFilterType::Pointer intCastFilter;
174 typename ULongCastFilterType::Pointer ulongCastFilter;
175 typename LongCastFilterType::Pointer longCastFilter;
176 typename FloatCastFilterType::Pointer floatCastFilter;
177 typename DoubleCastFilterType::Pointer doubleCastFilter;
179 switch ( m_ComponentType )
181 case ImageIOBase::UCHAR:
182 ucharWriter = UCharWriterType::New();
183 ucharCastFilter = UCharCastFilterType::New();
184 ucharWriter->SetFileName( m_FileName );
185 ucharCastFilter->SetInput( inputPtr );
186 ucharWriter->SetInput( ucharCastFilter->GetOutput() );
187 ucharWriter->SetImageIO( this->GetImageIO() );
188 ucharWriter->SetIORegion( this->GetIORegion() );
189 ucharWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
190 ucharWriter->SetUseCompression( this->GetUseCompression() );
191 ucharWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
192 ucharWriter->Update();
194 case ImageIOBase::CHAR:
195 charWriter = CharWriterType::New();
196 charCastFilter = CharCastFilterType::New();
197 charWriter->SetFileName( m_FileName );
198 charCastFilter->SetInput( inputPtr );
199 charWriter->SetInput( charCastFilter->GetOutput() );
200 charWriter->SetImageIO( this->GetImageIO() );
201 charWriter->SetIORegion( this->GetIORegion() );
202 charWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
203 charWriter->SetUseCompression( this->GetUseCompression() );
204 charWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
205 charWriter->Update();
207 case ImageIOBase::USHORT:
208 ushortWriter = UShortWriterType::New();
209 ushortCastFilter = UShortCastFilterType::New();
210 ushortWriter->SetFileName( m_FileName );
211 ushortCastFilter->SetInput( inputPtr );
212 ushortWriter->SetInput( ushortCastFilter->GetOutput() );
213 ushortWriter->SetImageIO( this->GetImageIO() );
214 ushortWriter->SetIORegion( this->GetIORegion() );
215 ushortWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
216 ushortWriter->SetUseCompression( this->GetUseCompression() );
217 ushortWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
218 ushortWriter->Update();
220 case ImageIOBase::SHORT:
221 shortWriter = ShortWriterType::New();
222 shortCastFilter = ShortCastFilterType::New();
223 shortWriter->SetFileName( m_FileName );
224 shortCastFilter->SetInput( inputPtr );
225 shortWriter->SetInput( shortCastFilter->GetOutput() );
226 shortWriter->SetImageIO( this->GetImageIO() );
227 shortWriter->SetIORegion( this->GetIORegion() );
228 shortWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
229 shortWriter->SetUseCompression( this->GetUseCompression() );
230 shortWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
231 shortWriter->Update();
233 case ImageIOBase::UINT:
234 uintWriter = UIntWriterType::New();
235 uintCastFilter = UIntCastFilterType::New();
236 uintWriter->SetFileName( m_FileName );
237 uintCastFilter->SetInput( inputPtr );
238 uintWriter->SetInput( uintCastFilter->GetOutput() );
239 uintWriter->SetImageIO( this->GetImageIO() );
240 uintWriter->SetIORegion( this->GetIORegion() );
241 uintWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
242 uintWriter->SetUseCompression( this->GetUseCompression() );
243 uintWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
244 uintWriter->Update();
246 case ImageIOBase::INT:
247 intWriter = IntWriterType::New();
248 intCastFilter = IntCastFilterType::New();
249 intWriter->SetFileName( m_FileName );
250 intCastFilter->SetInput( inputPtr );
251 intWriter->SetInput( intCastFilter->GetOutput() );
252 intWriter->SetImageIO( this->GetImageIO() );
253 intWriter->SetIORegion( this->GetIORegion() );
254 intWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
255 intWriter->SetUseCompression( this->GetUseCompression() );
256 intWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
259 case ImageIOBase::ULONG:
260 ulongWriter = ULongWriterType::New();
261 ulongCastFilter = ULongCastFilterType::New();
262 ulongWriter->SetFileName( m_FileName );
263 ulongCastFilter->SetInput( inputPtr );
264 ulongWriter->SetInput( ulongCastFilter->GetOutput() );
265 ulongWriter->SetImageIO( this->GetImageIO() );
266 ulongWriter->SetIORegion( this->GetIORegion() );
267 ulongWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
268 ulongWriter->SetUseCompression( this->GetUseCompression() );
269 ulongWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
270 ulongWriter->Update();
272 case ImageIOBase::LONG:
273 longWriter = LongWriterType::New();
274 longCastFilter = LongCastFilterType::New();
275 longWriter->SetFileName( m_FileName );
276 longCastFilter->SetInput( inputPtr );
277 longWriter->SetInput( longCastFilter->GetOutput() );
278 longWriter->SetImageIO( this->GetImageIO() );
279 longWriter->SetIORegion( this->GetIORegion() );
280 longWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
281 longWriter->SetUseCompression( this->GetUseCompression() );
282 longWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
283 longWriter->Update();
285 case ImageIOBase::FLOAT:
286 floatWriter = FloatWriterType::New();
287 floatCastFilter = FloatCastFilterType::New();
288 floatWriter->SetFileName( m_FileName );
289 floatCastFilter->SetInput( inputPtr );
290 floatWriter->SetInput( floatCastFilter->GetOutput() );
291 floatWriter->SetImageIO( this->GetImageIO() );
292 floatWriter->SetIORegion( this->GetIORegion() );
293 floatWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
294 floatWriter->SetUseCompression( this->GetUseCompression() );
295 floatWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
296 floatWriter->Update();
298 case ImageIOBase::DOUBLE:
299 doubleWriter = DoubleWriterType::New();
300 doubleCastFilter = DoubleCastFilterType::New();
301 doubleWriter->SetFileName( m_FileName );
302 doubleCastFilter->SetInput( inputPtr );
303 doubleWriter->SetInput( doubleCastFilter->GetOutput() );
304 doubleWriter->SetImageIO( this->GetImageIO() );
305 doubleWriter->SetIORegion( this->GetIORegion() );
306 doubleWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
307 doubleWriter->SetUseCompression( this->GetUseCompression() );
308 doubleWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
309 doubleWriter->Update();
319 template <
class TInputImage>
324 Superclass::PrintSelf(os,indent);
326 os << indent <<
"File Name: " 327 << (m_FileName.data() ? m_FileName.data() :
"(none)") << std::endl;
329 os << indent <<
"Image IO: ";
330 if ( m_ImageIO.IsNull() )
336 os << m_ImageIO <<
"\n";
339 os << indent <<
"IO Region: " << m_PasteIORegion <<
"\n";
340 os << indent <<
"Number of Stream Divisions: " << m_NumberOfStreamDivisions <<
"\n";
342 if (m_UseCompression)
344 os << indent <<
"Compression: On\n";
348 os << indent <<
"Compression: Off\n";
351 if (m_UseInputMetaDataDictionary)
353 os << indent <<
"UseInputMetaDataDictionary: On\n";
357 os << indent <<
"UseInputMetaDataDictionary: Off\n";
360 if (m_FactorySpecifiedImageIO)
362 os << indent <<
"FactorySpecifiedmageIO: On\n";
366 os << indent <<
"FactorySpecifiedmageIO: Off\n";
void SetIORegion(const ImageIORegion ®ion)
const InputImageType * GetInput(void)
virtual void SetInput(const InputImageType *input)
TInputImage InputImageType
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
void GenerateData(void) ITK_OVERRIDE