@@ -400,6 +400,50 @@ TestVectorImageCast2()
400400}
401401
402402
403+ bool
404+ TestVectorImageCast3 ()
405+ {
406+ // This function casts an Image<Vector<float, 3>, 3>
407+ // to a VectorImage<float, 3>
408+ std::cout << " Casting from an Image<Vector<float,3>, 3> to VectorImage<float, 3> ... " ;
409+
410+ using VectorFloatImageType = itk::Image<itk::Vector<float , 3 >, 3 >;
411+ using FloatVectorImageType = itk::VectorImage<float , 3 >;
412+
413+ // Create a 1x3 image of 2D vectors
414+ auto image = VectorFloatImageType::New ();
415+
416+ constexpr itk::Size<3 > size{ { 1 , 1 , 4 } };
417+ const itk::ImageRegion<3 > region{ size };
418+ image->SetRegions (region);
419+ image->AllocateInitialized ();
420+ VectorFloatImageType::PixelType vec{ { 1.3 , 5.3 , 6.4 } };
421+ // Only the first pixel will be the vector (1.3, 5.3, 6.4)
422+ image->SetPixel (itk::Index<3 >(), vec);
423+
424+ using CastImageFilterType = itk::CastImageFilter<VectorFloatImageType, FloatVectorImageType>;
425+ auto castImageFilter = CastImageFilterType::New ();
426+ castImageFilter->SetInput (image);
427+ castImageFilter->SetNumberOfWorkUnits (1 );
428+ castImageFilter->Update ();
429+
430+ bool success = true ;
431+ if (std::memcmp (castImageFilter->GetOutput ()->GetBufferPointer (),
432+ image->GetBufferPointer (),
433+ sizeof (float ) * size.CalculateProductOfElements ()) == 0 )
434+ {
435+ std::cout << " [PASSED]" << std::endl;
436+ }
437+ else
438+ {
439+ std::cout << " [FAILED]" << std::endl;
440+ success = false ;
441+ }
442+
443+ return success;
444+ }
445+
446+
403447int
404448itkCastImageFilterTest (int , char *[])
405449{
@@ -431,6 +475,7 @@ itkCastImageFilterTest(int, char *[])
431475 success &= TestCastFrom<double >();
432476 success &= TestVectorImageCast1 ();
433477 success &= TestVectorImageCast2 ();
478+ success &= TestVectorImageCast3 ();
434479
435480 std::cout << std::endl;
436481 if (!success)
0 commit comments