OTB  7.1.0
Orfeo Toolbox
otbComplexToVectorImageCastFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbComplexToVectorImageCastFilter_h
22 #define otbComplexToVectorImageCastFilter_h
23 
24 #include "itkUnaryFunctorImageFilter.h"
25 #include "vnl/vnl_math.h"
26 #include "itkVariableLengthVector.h"
27 
28 
29 namespace otb
30 {
31 
42 namespace Functor
43 {
44 
45 template <class TInput, class TOutput>
47 {
48 public:
49  typedef typename TOutput::ValueType OutputValueType;
50 
52  {
53  }
55  {
56  }
57 
58  inline TOutput operator()(const TInput& A) const
59  {
60  TOutput output;
61  output.SetSize(2);
62 
63  output[0] = static_cast<OutputValueType>(A.real());
64  output[1] = static_cast<OutputValueType>(A.imag());
65 
66  return output;
67  }
68 };
69 
70 
71 template <class TInput, class TOutput>
73 {
74 public:
75  typedef typename TOutput::ValueType OutputValueType;
76  typedef typename TInput::ValueType ValueType;
77  typedef itk::VariableLengthVector<ValueType> TestType;
78 
80  {
81  }
83  {
84  }
85 
86  inline TOutput operator()(const TInput& A) const
87  {
88  TOutput output;
89  output.SetSize(2 * A.Size());
90 
91  for (unsigned int i = 0; i < A.Size(); ++i)
92  {
93  output[2 * i] = static_cast<OutputValueType>(A[i].real());
94  output[2 * i + 1] = static_cast<OutputValueType>(A[i].imag());
95  }
96 
97  return output;
98  }
99 };
100 
101 
102 template <class TInput, class TOutput>
104 {
105 public:
107 };
108 
109 
110 template <class TInput, class TOutput>
111 class ComplexToVector<itk::VariableLengthVector<TInput>, TOutput>
112 {
113 public:
115 };
116 }
117 
118 
119 template <class TInputImage, class TOutputImage>
121  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
122  typename Functor::ComplexToVector<typename TInputImage::PixelType, typename TOutputImage::PixelType>::FunctorType>
123 {
124 public:
127  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
130  typedef itk::SmartPointer<Self> Pointer;
131  typedef itk::SmartPointer<const Self> ConstPointer;
132 
134  itkNewMacro(Self);
135 
137  itkTypeMacro(ComplexToVectorImageCastFilter, itk::UnaryFunctorImageFilter);
138 
139  typedef typename TInputImage::PixelType InputPixelType;
140  typedef typename TOutputImage::PixelType OutputPixelType;
141 
142 
143 protected:
145  {
146  }
148  {
149  }
150 
151  template <class T>
152  bool PixelIsSingle(const T& /*dummy*/)
153  {
154  return true;
155  }
156 
157  template <class T>
158  bool PixelIsSingle(const itk::VariableLengthVector<T>& /*dummy*/)
159  {
160  return false;
161  }
162 
164  {
165  Superclass::GenerateOutputInformation();
166  InputPixelType dummy;
167  if (!this->PixelIsSingle(dummy))
168  {
169  this->GetOutput()->SetNumberOfComponentsPerPixel(2 * this->GetInput()->GetNumberOfComponentsPerPixel());
170  }
171  }
172 
173 private:
174  ComplexToVectorImageCastFilter(const Self&) = delete;
175  void operator=(const Self&) = delete;
176 };
177 
178 } // end namespace otb
179 
180 
181 #endif
SingleComplexToVector< TInput, TOutput > FunctorType
Transform a complex image into a 2 channels vector image. The first channel is the real part...
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, typename Functor::ComplexToVector< typename TInputImage::PixelType, typename TOutputImage::PixelType >::FunctorType > Superclass
bool PixelIsSingle(const itk::VariableLengthVector< T > &)
VectorComplexToVector< itk::VariableLengthVector< TInput >, TOutput > FunctorType
itk::VariableLengthVector< ValueType > TestType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.