22 #ifndef otbConvertPixelBuffer_hxx
23 #define otbConvertPixelBuffer_hxx
26 #include "itkConvertPixelBuffer.h"
30 template <
typename InputPixelType,
typename OutputPixelType,
class OutputConvertTraits>
32 OutputPixelType* outputData,
size_t size)
37 ConvertGrayToComplex(inputData, outputData, size);
42 itk::ConvertPixelBuffer<InputPixelType, OutputPixelType, OutputConvertTraits>::Convert(inputData, inputNumberOfComponents, outputData, size);
47 template <
typename InputPixelType,
typename OutputPixelType,
class OutputConvertTraits>
51 InputPixelType* endInput = inputData + size;
52 while (inputData != endInput)
54 OutputConvertTraits::SetNthComponent(0, *outputData,
static_cast<OutputComponentType>(*inputData));
63 template <
typename InputType,
typename OutputType>
64 OutputType
ComplexCast(
const std::complex<InputType>& in,
const OutputType& itkNotUsed(dummy))
66 typedef typename itk::NumericTraits<std::complex<InputType>>::RealType RealType;
67 typedef typename itk::NumericTraits<std::complex<InputType>>::ScalarRealType ScalarRealType;
69 RealType inReal(
static_cast<ScalarRealType
>(in.real()),
static_cast<ScalarRealType
>(in.imag()));
71 return static_cast<OutputType
>(std::abs(inReal));
74 template <
typename InputType,
typename OutputType>
75 std::complex<OutputType>
ComplexCast(
const std::complex<InputType>& in,
const std::complex<OutputType>& itkNotUsed(dummy))
77 typedef typename itk::NumericTraits<std::complex<InputType>>::RealType RealType;
78 typedef typename itk::NumericTraits<std::complex<InputType>>::ScalarRealType ScalarRealType;
80 RealType inReal(
static_cast<ScalarRealType
>(in.real()),
static_cast<ScalarRealType
>(in.imag()));
82 return static_cast<std::complex<OutputType>
>(inReal);
85 template <
typename InputPixelType,
typename OutputPixelType,
class OutputConvertTraits>
87 int itkNotUsed(inputNumberOfComponents),
88 OutputPixelType* outputData,
size_t size)
90 OutputPixelType dummy;
91 std::complex<InputPixelType>* endInput = inputData + size;
92 while (inputData != endInput)
94 OutputConvertTraits::SetNthComponent(0, *outputData,
static_cast<OutputPixelType
>(
ComplexCast(*inputData, dummy)));
100 template <
typename InputPixelType,
typename OutputPixelType,
class OutputConvertTraits>
102 OutputPixelType* outputData,
size_t size)
104 itk::ConvertPixelBuffer<InputPixelType, OutputPixelType, OutputConvertTraits>::ConvertVectorImage(inputData, inputNumberOfComponents, outputData, size);
107 template <
typename InputPixelType,
typename OutputPixelType,
class OutputConvertTraits>
109 int inputNumberOfComponents,
110 OutputPixelType* outputData,
size_t size)
112 size_t length = size * (size_t)inputNumberOfComponents;
113 for (
size_t i = 0; i < length / 2; i++)
115 OutputConvertTraits::SetNthComponent(0, *outputData, (*inputData).real());
117 OutputConvertTraits::SetNthComponent(0, *outputData, (*inputData).imag());
123 template <
typename InputPixelType,
typename OutputPixelType,
class OutputConvertTraits>
125 std::complex<InputPixelType>* inputData,
int inputNumberOfComponents, OutputPixelType* outputData,
size_t size)
127 size_t length = size * (size_t)inputNumberOfComponents;
128 OutputPixelType dummy;
129 for (
size_t i = 0; i < length; i++)
131 OutputConvertTraits::SetNthComponent(0, *outputData,
ComplexCast(*inputData, dummy));