VMTK
Loading...
Searching...
No Matches
vtkvmtkITKImageWriter Class Reference

Write vtkImageData to a file using an ITK image IO. More...

#include <vtkvmtkITKImageWriter.h>

Inheritance diagram for vtkvmtkITKImageWriter:
[legend]
Collaboration diagram for vtkvmtkITKImageWriter:
[legend]

Public Types

typedef vtkImageAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkITKImageWriter * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
void SetFileName (const char *)
char * GetFileName ()
virtual int GetUseCompression ()
 use compression if possible
virtual void SetUseCompression (int)
virtual void UseCompressionOn ()
virtual void UseCompressionOff ()
virtual char * GetImageIOClassName ()
 Set/Get the ImageIO class name.
virtual void SetImageIOClassName (const char *)
void Write ()
 The main interface which triggers the writer to start.
void SetRasToIJKMatrix (vtkMatrix4x4 *mat)
 Set orienation matrix.
void SetMeasurementFrameMatrix (vtkMatrix4x4 *mat)
 Set orienation matrix.

Static Public Member Functions

static vtkvmtkITKImageWriter * New ()
static int IsTypeOf (const char *type)
static vtkvmtkITKImageWriter * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkITKImageWriter ()
 ~vtkvmtkITKImageWriter ()

Protected Attributes

char * FileName
vtkMatrix4x4 * RasToIJKMatrix
vtkMatrix4x4 * MeasurementFrameMatrix
int UseCompression
char * ImageIOClassName

Detailed Description

Write vtkImageData to a file using an ITK image IO.

vtkvmtkITKImageWriter converts its input vtkImageData to an ITK image (choosing the ITK pixel type from the VTK scalar type) and writes it with itk::ImageFileWriter, so it supports any file format for which an ITK ImageIO is available (e.g. NRRD, NIfTI, MetaImage, DICOM). The orientation of the written image can be set explicitly via SetRasToIJKMatrix() and, for diffusion data, SetMeasurementFrameMatrix().

Definition at line 37 of file vtkvmtkITKImageWriter.h.

Member Typedef Documentation

◆ Superclass

typedef vtkImageAlgorithm vtkvmtkITKImageWriter::Superclass

Definition at line 41 of file vtkvmtkITKImageWriter.h.

Constructor & Destructor Documentation

◆ vtkvmtkITKImageWriter()

vtkvmtkITKImageWriter::vtkvmtkITKImageWriter ( )
protected

Definition at line 245 of file vtkvmtkITKImageWriter.cxx.

246{
247 this->FileName = NULL;
248 this->RasToIJKMatrix = NULL;
249 this->MeasurementFrameMatrix = NULL;
250 this->UseCompression = 0;
251 this->ImageIOClassName = NULL;
252}
vtkMatrix4x4 * MeasurementFrameMatrix

◆ ~vtkvmtkITKImageWriter()

vtkvmtkITKImageWriter::~vtkvmtkITKImageWriter ( )
protected

Definition at line 256 of file vtkvmtkITKImageWriter.cxx.

257{
258 // get rid of memory allocated for file names
259 if (this->FileName)
260 {
261 delete [] this->FileName;
262 this->FileName = NULL;
263 }
264
265 if (this->ImageIOClassName)
266 {
267 delete [] this->ImageIOClassName;
268 this->ImageIOClassName = NULL;
269 }
270}

Member Function Documentation

◆ New()

vtkvmtkITKImageWriter * vtkvmtkITKImageWriter::New ( )
static

◆ IsTypeOf()

int vtkvmtkITKImageWriter::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkITKImageWriter::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkITKImageWriter * vtkvmtkITKImageWriter::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkITKImageWriter::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkITKImageWriter * vtkvmtkITKImageWriter::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkITKImageWriter::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 274 of file vtkvmtkITKImageWriter.cxx.

275{
276 this->Superclass::PrintSelf(os,indent);
277
278 os << indent << "FileName: " <<
279 (this->FileName ? this->FileName : "(none)") << "\n";
280 os << indent << "ImageIOClassName: " <<
281 (this->ImageIOClassName ? this->ImageIOClassName : "(none)") << "\n";
282}

◆ SetFileName()

void vtkvmtkITKImageWriter::SetFileName ( const char * name)

Specify file name for the image file. You should specify either a FileName or a FilePrefix. Use FilePrefix if the data is stored in multiple files.

Definition at line 287 of file vtkvmtkITKImageWriter.cxx.

288{
289 if ( this->FileName && name && (!strcmp(this->FileName,name)))
290 {
291 return;
292 }
293 if (!name && !this->FileName)
294 {
295 return;
296 }
297 if (this->FileName)
298 {
299 delete [] this->FileName;
300 }
301
302 this->FileName = new char[strlen(name) + 1];
303 strcpy(this->FileName, name);
304 this->Modified();
305}

◆ GetFileName()

char * vtkvmtkITKImageWriter::GetFileName ( )
inline

Definition at line 50 of file vtkvmtkITKImageWriter.h.

50 {
51 return FileName;
52 }

◆ GetUseCompression()

virtual int vtkvmtkITKImageWriter::GetUseCompression ( )
virtual

use compression if possible

◆ SetUseCompression()

virtual void vtkvmtkITKImageWriter::SetUseCompression ( int )
virtual

◆ UseCompressionOn()

virtual void vtkvmtkITKImageWriter::UseCompressionOn ( )
virtual

◆ UseCompressionOff()

virtual void vtkvmtkITKImageWriter::UseCompressionOff ( )
virtual

◆ GetImageIOClassName()

virtual char * vtkvmtkITKImageWriter::GetImageIOClassName ( )
virtual

Set/Get the ImageIO class name.

◆ SetImageIOClassName()

virtual void vtkvmtkITKImageWriter::SetImageIOClassName ( const char * )
virtual

◆ Write()

void vtkvmtkITKImageWriter::Write ( )

The main interface which triggers the writer to start.

Definition at line 309 of file vtkvmtkITKImageWriter.cxx.

310{
311 vtkImageData *inputImage = this->GetImageDataInput(0);
312 vtkPointData* pointData = inputImage->GetPointData();
313
314 if ( inputImage == NULL ||
315 pointData == NULL )
316 {
317 vtkErrorMacro(<<"vtkvmtkITKImageWriter: No image to write");
318 return;
319 }
320 if ( ! this->FileName )
321 {
322 vtkErrorMacro(<<"vtkvmtkITKImageWriter: Please specify a FileName");
323 return;
324 }
325
326 if (this->GetOutputInformation(0))
327 {
328 this->GetOutputInformation(0)->Set(
329 vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(),
330 this->GetOutputInformation(0)->Get(
331 vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()), 6);
332 }
333
334 int inputDataType =
335 pointData->GetScalars() ? pointData->GetScalars()->GetDataType() :
336 pointData->GetTensors() ? pointData->GetTensors()->GetDataType() :
337 pointData->GetVectors() ? pointData->GetVectors()->GetDataType() :
338 pointData->GetNormals() ? pointData->GetNormals()->GetDataType() :
339 0;
340 int inputNumberOfScalarComponents =
341 pointData->GetScalars() ? pointData->GetScalars()->GetNumberOfComponents() :
342 pointData->GetTensors() ? pointData->GetTensors()->GetNumberOfComponents() :
343 pointData->GetVectors() ? pointData->GetVectors()->GetNumberOfComponents() :
344 pointData->GetNormals() ? pointData->GetNormals()->GetNumberOfComponents() :
345 0;
346
347 if (inputNumberOfScalarComponents == 1)
348 {
349 // take into consideration the scalar type
350 switch (inputDataType)
351 {
352 case VTK_DOUBLE:
353 {
354 ITKWriteVTKImage<double>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
355 }
356 break;
357 case VTK_FLOAT:
358 {
359 ITKWriteVTKImage<float>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
360 }
361 break;
362 case VTK_LONG:
363 {
364 ITKWriteVTKImage<long>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
365 }
366 break;
367 case VTK_UNSIGNED_LONG:
368 {
369 ITKWriteVTKImage<unsigned long>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
370 }
371 break;
372 case VTK_INT:
373 {
374 ITKWriteVTKImage<int>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
375 }
376 break;
377 case VTK_UNSIGNED_INT:
378 {
379 ITKWriteVTKImage<unsigned int>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
380 }
381 break;
382 case VTK_SHORT:
383 {
384 ITKWriteVTKImage<short>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
385 }
386 break;
387 case VTK_UNSIGNED_SHORT:
388 {
389 ITKWriteVTKImage<unsigned short>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
390 }
391 break;
392 case VTK_CHAR:
393 {
394 ITKWriteVTKImage<char>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
395 }
396 break;
397 case VTK_UNSIGNED_CHAR:
398 {
399 ITKWriteVTKImage<unsigned char>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
400 }
401 break;
402 default:
403 vtkErrorMacro(<< "Execute: Unknown output ScalarType");
404 return;
405 }
406 } // scalar
407 else if (inputNumberOfScalarComponents == 3)
408 {
409 // take into consideration the scalar type
410 switch (inputDataType)
411 {
412 case VTK_DOUBLE:
413 {
414 typedef itk::Vector<double, 3> VectorPixelType;
415 ITKWriteVTKImage<VectorPixelType>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
416 }
417 break;
418 case VTK_FLOAT:
419 {
420 typedef itk::Vector<float, 3> VectorPixelType;
421 ITKWriteVTKImage<VectorPixelType>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
422 }
423 break;
424 case VTK_UNSIGNED_SHORT:
425 {
426 typedef itk::Vector<unsigned short, 3> VectorPixelType;
427 ITKWriteVTKImage<VectorPixelType>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
428 }
429 break;
430 case VTK_UNSIGNED_CHAR:
431 {
432 typedef itk::Vector<unsigned char, 3> VectorPixelType;
433 ITKWriteVTKImage<VectorPixelType>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
434 }
435 break;
436 default:
437 vtkErrorMacro(<< "Execute: Unknown output ScalarType");
438 return;
439 }
440 } // vector
441 else if (inputNumberOfScalarComponents == 4)
442 {
443 // take into consideration the scalar type
444 switch (inputDataType)
445 {
446 case VTK_DOUBLE:
447 {
448 typedef itk::Vector<double, 4> VectorPixelType;
449 ITKWriteVTKImage<VectorPixelType>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
450 }
451 break;
452 case VTK_FLOAT:
453 {
454 typedef itk::Vector<float, 4> VectorPixelType;
455 ITKWriteVTKImage<VectorPixelType>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
456 }
457 break;
458 case VTK_UNSIGNED_SHORT:
459 {
460 typedef itk::Vector<unsigned short, 4> VectorPixelType;
461 ITKWriteVTKImage<VectorPixelType>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
462 }
463 break;
464 case VTK_UNSIGNED_CHAR:
465 {
466 typedef itk::Vector<unsigned char, 4> VectorPixelType;
467 ITKWriteVTKImage<VectorPixelType>(this, inputImage, this->GetFileName(), this->RasToIJKMatrix);
468 }
469 break;
470 default:
471 vtkErrorMacro(<< "Execute: Unknown output ScalarType");
472 return;
473 }
474 } // 4-vector
475 else if (inputNumberOfScalarComponents == 9)
476 {
477 // take into consideration the scalar type
478 switch (inputDataType)
479 {
480 case VTK_FLOAT:
481 {
482 typedef itk::DiffusionTensor3D<float> TensorPixelType;
483 vtkNew<vtkImageData> outImage;
484 outImage->SetDimensions(inputImage->GetDimensions());
485 outImage->SetOrigin(0, 0, 0);
486 outImage->SetSpacing(1, 1, 1);
487 outImage->AllocateScalars(VTK_FLOAT, 6);
488 vtkFloatArray* out = vtkFloatArray::SafeDownCast(outImage->GetPointData()->GetScalars());
489 vtkFloatArray* in = vtkFloatArray::SafeDownCast(inputImage->GetPointData()->GetTensors());
490 float inValue[9];
491 float outValue[6];
492 for(int i=0; i<out->GetNumberOfTuples(); i++)
493 {
494 in->GetTypedTuple(i, inValue);
495 //ITK expect tensors saved in upper-triangular format
496 outValue[0] = inValue[0];
497 outValue[1] = inValue[1];
498 outValue[2] = inValue[2];
499 outValue[3] = inValue[4];
500 outValue[4] = inValue[7];
501 outValue[5] = inValue[8];
502 out->SetTuple(i, outValue);
503 }
504
505 ITKWriteVTKImage<TensorPixelType>(this, outImage.GetPointer(),
506 this->GetFileName(), this->RasToIJKMatrix, this->MeasurementFrameMatrix);
507 }
508 inputImage->GetPointData()->SetScalars(NULL);
509 break;
510 default:
511 vtkErrorMacro(<< "Execute: Unknown output ScalarType");
512 return;
513 }
514 }
515 else
516 {
517 vtkErrorMacro(<< "Can only export 1 or 3 component images, current image has " << inputNumberOfScalarComponents << " components");
518 return;
519 }
520}
void ITKWriteVTKImage(vtkvmtkITKImageWriter *self, vtkImageData *inputImage, char *fileName, vtkMatrix4x4 *rasToIjkMatrix, vtkMatrix4x4 *MeasurementFrameMatrix=NULL)

◆ SetRasToIJKMatrix()

void vtkvmtkITKImageWriter::SetRasToIJKMatrix ( vtkMatrix4x4 * mat)
inline

Set orienation matrix.

Definition at line 70 of file vtkvmtkITKImageWriter.h.

70 {
71 RasToIJKMatrix = mat;
72 }

◆ SetMeasurementFrameMatrix()

void vtkvmtkITKImageWriter::SetMeasurementFrameMatrix ( vtkMatrix4x4 * mat)
inline

Set orienation matrix.

Definition at line 75 of file vtkvmtkITKImageWriter.h.

75 {
77 }

Member Data Documentation

◆ FileName

char* vtkvmtkITKImageWriter::FileName
protected

Definition at line 83 of file vtkvmtkITKImageWriter.h.

◆ RasToIJKMatrix

vtkMatrix4x4* vtkvmtkITKImageWriter::RasToIJKMatrix
protected

Definition at line 84 of file vtkvmtkITKImageWriter.h.

◆ MeasurementFrameMatrix

vtkMatrix4x4* vtkvmtkITKImageWriter::MeasurementFrameMatrix
protected

Definition at line 85 of file vtkvmtkITKImageWriter.h.

◆ UseCompression

int vtkvmtkITKImageWriter::UseCompression
protected

Definition at line 86 of file vtkvmtkITKImageWriter.h.

◆ ImageIOClassName

char* vtkvmtkITKImageWriter::ImageIOClassName
protected

Definition at line 87 of file vtkvmtkITKImageWriter.h.


The documentation for this class was generated from the following files: