14 #ifndef __itkCastVectorImageFileWriter_hxx 15 #define __itkCastVectorImageFileWriter_hxx 17 #include "itkImageFileWriter.h" 18 #include "itkDataObject.h" 19 #include "itkObjectFactoryBase.h" 20 #include "itkImageIOFactory.h" 21 #include "itkCommand.h" 22 #include "vnl/vnl_vector.h" 23 #include "itkVectorImage.h" 24 #include "itkImageRegionConstIterator.h" 25 #include "itkImageRegionIterator.h" 26 #include "itkCastImageFilter.h" 32 template <
class TInputImage>
35 m_PasteIORegion(TInputImage::ImageDimension)
37 m_UseCompression =
false;
38 m_UseInputMetaDataDictionary =
true;
39 m_FactorySpecifiedImageIO =
false;
40 m_UserSpecifiedIORegion =
false;
41 m_UserSpecifiedImageIO =
false;
42 m_NumberOfStreamDivisions = 1;
43 m_ComponentType = ImageIOBase::DOUBLE;
47 template <
class TInputImage>
54 template <
class TInputImage>
60 this->ProcessObject::SetNthInput(0,
61 const_cast<TInputImage *>(input ) );
66 template <
class TInputImage>
71 if (this->GetNumberOfInputs() < 1)
76 return static_cast<TInputImage*
> 77 (this->ProcessObject::GetInput(0));
81 template <
class TInputImage>
86 return static_cast<TInputImage*
> (this->ProcessObject::GetInput(idx));
90 template <
class TInputImage>
95 itkDebugMacro(
"setting IORegion to " << region );
96 if ( m_PasteIORegion != region)
98 m_PasteIORegion = region;
100 m_UserSpecifiedIORegion =
true;
105 template <
class TInputImage>
110 itkDebugMacro( <<
"Writing an image file" );
111 this->GenerateData();
116 template <
class TInputImage>
123 itkDebugMacro(<<
"Writing file: " << m_FileName);
128 typedef VectorImage<unsigned char, TInputImage::ImageDimension> UCharImageType;
129 typedef VectorImage<char, TInputImage::ImageDimension> CharImageType;
130 typedef VectorImage<unsigned short, TInputImage::ImageDimension> UShortImageType;
131 typedef VectorImage<short, TInputImage::ImageDimension> ShortImageType;
132 typedef VectorImage<unsigned int, TInputImage::ImageDimension> UIntImageType;
133 typedef VectorImage<int, TInputImage::ImageDimension> IntImageType;
134 typedef VectorImage<unsigned long, TInputImage::ImageDimension> ULongImageType;
135 typedef VectorImage<long, TInputImage::ImageDimension> LongImageType;
136 typedef VectorImage<float, TInputImage::ImageDimension> FloatImageType;
137 typedef VectorImage<double, TInputImage::ImageDimension> DoubleImageType;
139 typedef ImageFileWriter<UCharImageType> UCharWriterType;
140 typedef ImageFileWriter<CharImageType> CharWriterType;
141 typedef ImageFileWriter<UShortImageType> UShortWriterType;
142 typedef ImageFileWriter<ShortImageType> ShortWriterType;
143 typedef ImageFileWriter<UIntImageType> UIntWriterType;
144 typedef ImageFileWriter<IntImageType> IntWriterType;
145 typedef ImageFileWriter<ULongImageType> ULongWriterType;
146 typedef ImageFileWriter<LongImageType> LongWriterType;
147 typedef ImageFileWriter<FloatImageType> FloatWriterType;
148 typedef ImageFileWriter<DoubleImageType> DoubleWriterType;
150 typedef CastImageFilter<TInputImage, UCharImageType> UCharCastFilterType;
151 typedef CastImageFilter<TInputImage, CharImageType> CharCastFilterType;
152 typedef CastImageFilter<TInputImage, UShortImageType> UShortCastFilterType;
153 typedef CastImageFilter<TInputImage, ShortImageType> ShortCastFilterType;
154 typedef CastImageFilter<TInputImage, UIntImageType> UIntCastFilterType;
155 typedef CastImageFilter<TInputImage, IntImageType> IntCastFilterType;
156 typedef CastImageFilter<TInputImage, ULongImageType> ULongCastFilterType;
157 typedef CastImageFilter<TInputImage, LongImageType> LongCastFilterType;
158 typedef CastImageFilter<TInputImage, FloatImageType> FloatCastFilterType;
159 typedef CastImageFilter<TInputImage, DoubleImageType> DoubleCastFilterType;
161 typename UCharWriterType::Pointer ucharWriter;
162 typename CharWriterType::Pointer charWriter;
163 typename UShortWriterType::Pointer ushortWriter;
164 typename ShortWriterType::Pointer shortWriter;
165 typename UIntWriterType::Pointer uintWriter;
166 typename IntWriterType::Pointer intWriter;
167 typename ULongWriterType::Pointer ulongWriter;
168 typename LongWriterType::Pointer longWriter;
169 typename FloatWriterType::Pointer floatWriter;
170 typename DoubleWriterType::Pointer doubleWriter;
172 typename UCharCastFilterType::Pointer ucharCastFilter;
173 typename CharCastFilterType::Pointer charCastFilter;
174 typename UShortCastFilterType::Pointer ushortCastFilter;
175 typename ShortCastFilterType::Pointer shortCastFilter;
176 typename UIntCastFilterType::Pointer uintCastFilter;
177 typename IntCastFilterType::Pointer intCastFilter;
178 typename ULongCastFilterType::Pointer ulongCastFilter;
179 typename LongCastFilterType::Pointer longCastFilter;
180 typename FloatCastFilterType::Pointer floatCastFilter;
181 typename DoubleCastFilterType::Pointer doubleCastFilter;
183 switch ( m_ComponentType )
185 case ImageIOBase::UCHAR:
186 ucharWriter = UCharWriterType::New();
187 ucharCastFilter = UCharCastFilterType::New();
188 ucharWriter->SetFileName( m_FileName );
189 ucharCastFilter->SetInput( inputPtr );
190 ucharWriter->SetInput( ucharCastFilter->GetOutput() );
191 ucharWriter->SetImageIO( this->GetImageIO() );
192 ucharWriter->SetIORegion( this->GetIORegion() );
193 ucharWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
194 ucharWriter->SetUseCompression( this->GetUseCompression() );
195 ucharWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
196 ucharWriter->Update();
198 case ImageIOBase::CHAR:
199 charWriter = CharWriterType::New();
200 charCastFilter = CharCastFilterType::New();
201 charWriter->SetFileName( m_FileName );
202 charCastFilter->SetInput( inputPtr );
203 charWriter->SetInput( charCastFilter->GetOutput() );
204 charWriter->SetImageIO( this->GetImageIO() );
205 charWriter->SetIORegion( this->GetIORegion() );
206 charWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
207 charWriter->SetUseCompression( this->GetUseCompression() );
208 charWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
209 charWriter->Update();
211 case ImageIOBase::USHORT:
212 ushortWriter = UShortWriterType::New();
213 ushortCastFilter = UShortCastFilterType::New();
214 ushortWriter->SetFileName( m_FileName );
215 ushortCastFilter->SetInput( inputPtr );
216 ushortWriter->SetInput( ushortCastFilter->GetOutput() );
217 ushortWriter->SetImageIO( this->GetImageIO() );
218 ushortWriter->SetIORegion( this->GetIORegion() );
219 ushortWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
220 ushortWriter->SetUseCompression( this->GetUseCompression() );
221 ushortWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
222 ushortWriter->Update();
224 case ImageIOBase::SHORT:
225 shortWriter = ShortWriterType::New();
226 shortCastFilter = ShortCastFilterType::New();
227 shortWriter->SetFileName( m_FileName );
228 shortCastFilter->SetInput( inputPtr );
229 shortWriter->SetInput( shortCastFilter->GetOutput() );
230 shortWriter->SetImageIO( this->GetImageIO() );
231 shortWriter->SetIORegion( this->GetIORegion() );
232 shortWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
233 shortWriter->SetUseCompression( this->GetUseCompression() );
234 shortWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
235 shortWriter->Update();
237 case ImageIOBase::UINT:
238 uintWriter = UIntWriterType::New();
239 uintCastFilter = UIntCastFilterType::New();
240 uintWriter->SetFileName( m_FileName );
241 uintCastFilter->SetInput( inputPtr );
242 uintWriter->SetInput( uintCastFilter->GetOutput() );
243 uintWriter->SetImageIO( this->GetImageIO() );
244 uintWriter->SetIORegion( this->GetIORegion() );
245 uintWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
246 uintWriter->SetUseCompression( this->GetUseCompression() );
247 uintWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
248 uintWriter->Update();
250 case ImageIOBase::INT:
251 intWriter = IntWriterType::New();
252 intCastFilter = IntCastFilterType::New();
253 intWriter->SetFileName( m_FileName );
254 intCastFilter->SetInput( inputPtr );
255 intWriter->SetInput( intCastFilter->GetOutput() );
256 intWriter->SetImageIO( this->GetImageIO() );
257 intWriter->SetIORegion( this->GetIORegion() );
258 intWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
259 intWriter->SetUseCompression( this->GetUseCompression() );
260 intWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
263 case ImageIOBase::ULONG:
264 ulongWriter = ULongWriterType::New();
265 ulongCastFilter = ULongCastFilterType::New();
266 ulongWriter->SetFileName( m_FileName );
267 ulongCastFilter->SetInput( inputPtr );
268 ulongWriter->SetInput( ulongCastFilter->GetOutput() );
269 ulongWriter->SetImageIO( this->GetImageIO() );
270 ulongWriter->SetIORegion( this->GetIORegion() );
271 ulongWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
272 ulongWriter->SetUseCompression( this->GetUseCompression() );
273 ulongWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
274 ulongWriter->Update();
276 case ImageIOBase::LONG:
277 longWriter = LongWriterType::New();
278 longCastFilter = LongCastFilterType::New();
279 longWriter->SetFileName( m_FileName );
280 longCastFilter->SetInput( inputPtr );
281 longWriter->SetInput( longCastFilter->GetOutput() );
282 longWriter->SetImageIO( this->GetImageIO() );
283 longWriter->SetIORegion( this->GetIORegion() );
284 longWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
285 longWriter->SetUseCompression( this->GetUseCompression() );
286 longWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
287 longWriter->Update();
289 case ImageIOBase::FLOAT:
290 floatWriter = FloatWriterType::New();
291 floatCastFilter = FloatCastFilterType::New();
292 floatWriter->SetFileName( m_FileName );
293 floatCastFilter->SetInput( inputPtr );
294 floatWriter->SetInput( floatCastFilter->GetOutput() );
295 floatWriter->SetImageIO( this->GetImageIO() );
296 floatWriter->SetIORegion( this->GetIORegion() );
297 floatWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
298 floatWriter->SetUseCompression( this->GetUseCompression() );
299 floatWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
300 floatWriter->Update();
302 case ImageIOBase::DOUBLE:
303 doubleWriter = DoubleWriterType::New();
304 doubleCastFilter = DoubleCastFilterType::New();
305 doubleWriter->SetFileName( m_FileName );
306 doubleCastFilter->SetInput( inputPtr );
307 doubleWriter->SetInput( doubleCastFilter->GetOutput() );
308 doubleWriter->SetImageIO( this->GetImageIO() );
309 doubleWriter->SetIORegion( this->GetIORegion() );
310 doubleWriter->SetNumberOfStreamDivisions( this->GetNumberOfStreamDivisions() );
311 doubleWriter->SetUseCompression( this->GetUseCompression() );
312 doubleWriter->SetUseInputMetaDataDictionary( this->GetUseInputMetaDataDictionary() );
313 doubleWriter->Update();
323 template <
class TInputImage>
328 Superclass::PrintSelf(os,indent);
330 os << indent <<
"File Name: " 331 << (m_FileName.data() ? m_FileName.data() :
"(none)") << std::endl;
333 os << indent <<
"Image IO: ";
334 if ( m_ImageIO.IsNull() )
340 os << m_ImageIO <<
"\n";
343 os << indent <<
"IO Region: " << m_PasteIORegion <<
"\n";
344 os << indent <<
"Number of Stream Divisions: " << m_NumberOfStreamDivisions <<
"\n";
346 if (m_UseCompression)
348 os << indent <<
"Compression: On\n";
352 os << indent <<
"Compression: Off\n";
355 if (m_UseInputMetaDataDictionary)
357 os << indent <<
"UseInputMetaDataDictionary: On\n";
361 os << indent <<
"UseInputMetaDataDictionary: Off\n";
364 if (m_FactorySpecifiedImageIO)
366 os << indent <<
"FactorySpecifiedmageIO: On\n";
370 os << indent <<
"FactorySpecifiedmageIO: Off\n";
void GenerateData(void) ITK_OVERRIDE
void SetIORegion(const ImageIORegion ®ion)
CastVectorImageFileWriter()
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
~CastVectorImageFileWriter()
void SetInput(const InputImageType *input)
const InputImageType * GetInput(void)
TInputImage InputImageType