+ bool mVV;
+
+ private:
+ template <class InputImageType, bool isVector>
+ class UpdateWithSelectiveOutputType
+ {
+ public:
+ static bool Run(ImageConvertGenericFilter& filter, std::string outputPixelType)
+ {
+ if (IsSameType<char>(outputPixelType))
+ UpdateWithOutputType<char>(filter);
+ else if (IsSameType<uchar>(outputPixelType))
+ UpdateWithOutputType<uchar>(filter);
+ else if (IsSameType<short>(outputPixelType))
+ UpdateWithOutputType<short>(filter);
+ else if (IsSameType<ushort>(outputPixelType))
+ UpdateWithOutputType<ushort>(filter);
+ else if (IsSameType<int>(outputPixelType))
+ UpdateWithOutputType<int>(filter);
+ else if (IsSameType<float>(outputPixelType))
+ UpdateWithOutputType<float>(filter);
+ else if (IsSameType<double>(outputPixelType))
+ UpdateWithOutputType<double>(filter);
+ else
+ {
+ std::string list = CreateListOfTypes<float, double>();
+ std::cerr << "Error, I don't know the vector output type '" << outputPixelType
+ << "'. " << std::endl << "Known types are " << list << "." << std::endl;
+ return false;
+ }
+
+ return true;
+ }
+
+ private:
+
+ template <class OutputPixelType>
+ static void UpdateWithOutputType(ImageConvertGenericFilter& filter)
+ {
+ // Read
+ typename InputImageType::Pointer input =filter.template GetInput<InputImageType>(0);
+
+ // Typedef
+ typedef typename InputImageType::PixelType PixelType;
+
+ // Warning
+ filter.CheckTypes<PixelType, OutputPixelType>(filter.GetInputPixelTypeName(), filter.GetOutputPixelTypeName());
+
+ // Cast
+ typedef itk::Image<OutputPixelType,InputImageType::ImageDimension> OutputImageType;
+ typedef itk::CastImageFilter<InputImageType, OutputImageType> FilterType;
+ typename FilterType::Pointer cast_filter = FilterType::New();
+ cast_filter->SetInput(input);
+ cast_filter->Update();
+
+ // Write
+ filter.SetNextOutput<OutputImageType>(cast_filter->GetOutput());
+ }
+ };
+
+ template <class InputImageType>
+ class UpdateWithSelectiveOutputType<InputImageType, true>
+ {
+ public:
+ static bool Run(ImageConvertGenericFilter& filter, std::string outputPixelType)
+ {
+ /*
+ // RP: future conversions?
+ if (IsSameType<char>(outputPixelType))
+ UpdateWithOutputVectorType<char>();
+ else if (IsSameType<uchar>(outputPixelType))
+ UpdateWithOutputVectorType<uchar>();
+ else if (IsSameType<short>(outputPixelType))
+ UpdateWithOutputVectorType<short>();
+ else if (IsSameType<ushort>(outputPixelType))
+ UpdateWithOutputVectorType<ushort>();
+ else if (IsSameType<int>(outputPixelType))
+ UpdateWithOutputVectorType<int>();
+ else
+ */
+ if (IsSameType<float>(outputPixelType))
+ UpdateWithOutputVectorType<float>(filter);
+ else if (IsSameType<double>(outputPixelType))
+ UpdateWithOutputVectorType<double>(filter);
+ else
+ {
+ std::string list = CreateListOfTypes<float, double>();
+ std::cerr << "Error, I don't know the vector output type '" << outputPixelType
+ << "'. " << std::endl << "Known types are " << list << "." << std::endl;
+ return false;
+ }
+
+ return true;
+ }
+
+ private:
+
+ template <class OutputPixelType>
+ static void UpdateWithOutputVectorType(ImageConvertGenericFilter& filter)
+ {
+ // Read
+ typename InputImageType::Pointer input =filter.template GetInput<InputImageType>(0);
+
+ // Typedef
+ typedef typename InputImageType::PixelType::ValueType PixelType;
+
+ // Warning
+ filter.CheckTypes<PixelType, OutputPixelType>(filter.GetInputPixelTypeName(), filter.GetOutputPixelTypeName());
+
+ // Cast
+ typedef itk::Image<itk::Vector<OutputPixelType, InputImageType::PixelType::Dimension>, InputImageType::ImageDimension> OutputImageType;
+ typedef itk::VectorCastImageFilter<InputImageType, OutputImageType> FilterType;
+ typename FilterType::Pointer cast_filter = FilterType::New();
+ cast_filter->SetInput(input);
+ cast_filter->Update();
+
+ // Write
+ filter.SetNextOutput<OutputImageType>(cast_filter->GetOutput());
+ }
+ };