The main interface which triggers the writer to start.
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 }
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
350 switch (inputDataType)
351 {
352 case VTK_DOUBLE:
353 {
355 }
356 break;
357 case VTK_FLOAT:
358 {
360 }
361 break;
362 case VTK_LONG:
363 {
365 }
366 break;
367 case VTK_UNSIGNED_LONG:
368 {
370 }
371 break;
372 case VTK_INT:
373 {
375 }
376 break;
377 case VTK_UNSIGNED_INT:
378 {
380 }
381 break;
382 case VTK_SHORT:
383 {
385 }
386 break;
387 case VTK_UNSIGNED_SHORT:
388 {
390 }
391 break;
392 case VTK_CHAR:
393 {
395 }
396 break;
397 case VTK_UNSIGNED_CHAR:
398 {
400 }
401 break;
402 default:
403 vtkErrorMacro(<< "Execute: Unknown output ScalarType");
404 return;
405 }
406 }
407 else if (inputNumberOfScalarComponents == 3)
408 {
409
410 switch (inputDataType)
411 {
412 case VTK_DOUBLE:
413 {
414 typedef itk::Vector<double, 3> VectorPixelType;
416 }
417 break;
418 case VTK_FLOAT:
419 {
420 typedef itk::Vector<float, 3> VectorPixelType;
422 }
423 break;
424 case VTK_UNSIGNED_SHORT:
425 {
426 typedef itk::Vector<unsigned short, 3> VectorPixelType;
428 }
429 break;
430 case VTK_UNSIGNED_CHAR:
431 {
432 typedef itk::Vector<unsigned char, 3> VectorPixelType;
434 }
435 break;
436 default:
437 vtkErrorMacro(<< "Execute: Unknown output ScalarType");
438 return;
439 }
440 }
441 else if (inputNumberOfScalarComponents == 4)
442 {
443
444 switch (inputDataType)
445 {
446 case VTK_DOUBLE:
447 {
448 typedef itk::Vector<double, 4> VectorPixelType;
450 }
451 break;
452 case VTK_FLOAT:
453 {
454 typedef itk::Vector<float, 4> VectorPixelType;
456 }
457 break;
458 case VTK_UNSIGNED_SHORT:
459 {
460 typedef itk::Vector<unsigned short, 4> VectorPixelType;
462 }
463 break;
464 case VTK_UNSIGNED_CHAR:
465 {
466 typedef itk::Vector<unsigned char, 4> VectorPixelType;
468 }
469 break;
470 default:
471 vtkErrorMacro(<< "Execute: Unknown output ScalarType");
472 return;
473 }
474 }
475 else if (inputNumberOfScalarComponents == 9)
476 {
477
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
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
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)