OTB  6.7.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 
25 #include "vnl/vnl_math.h"
27 
28 
29 namespace otb
30 {
31 
42 namespace Functor {
43 
44 template<class TInput, class TOutput>
46 {
47 public:
48  typedef typename TOutput::ValueType OutputValueType;
49 
52 
53  inline TOutput operator()( const TInput & A ) const
54  {
55  TOutput output;
56  output.SetSize( 2 );
57 
58  output[0] = static_cast<OutputValueType>(A.real());
59  output[1] = static_cast<OutputValueType>(A.imag());
60 
61  return output;
62  }
63 };
64 
65 
66 template<class TInput, class TOutput>
68 {
69 public:
70  typedef typename TOutput::ValueType OutputValueType;
71  typedef typename TInput::ValueType ValueType;
73 
76 
77  inline TOutput operator()( const TInput & A ) const
78  {
79  TOutput output;
80  output.SetSize( 2*A.Size() );
81 
82  for(unsigned int i=0; i<A.Size(); ++i)
83  {
84  output[2*i] = static_cast<OutputValueType>(A[i].real());
85  output[2*i+1] = static_cast<OutputValueType>(A[i].imag());
86  }
87 
88  return output;
89  }
90 
91 };
92 
93 
94 template< class TInput, class TOutput >
96 {
97 public:
99 };
100 
101 
102 template< class TInput, class TOutput >
103 class ComplexToVector<itk::VariableLengthVector<TInput>, TOutput>
104 {
105 public:
107 };
108 
109 }
110 
111 
112 template <class TInputImage, class TOutputImage>
114  public
115 itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
116  typename Functor::ComplexToVector<
117  typename TInputImage::PixelType,
118  typename TOutputImage::PixelType>::FunctorType >
119 {
120 public:
124  TInputImage, TOutputImage,
125  typename Functor::ComplexToVector< typename TInputImage::PixelType,
126  typename TOutputImage::PixelType>::FunctorType > Superclass;
129 
131  itkNewMacro(Self);
132 
134  itkTypeMacro(ComplexToVectorImageCastFilter,
136 
137  typedef typename TInputImage::PixelType InputPixelType;
138  typedef typename TOutputImage::PixelType OutputPixelType;
139 
140 
141 protected:
144 
145  template<class T>
146  bool PixelIsSingle(const T& /*dummy*/)
147  {
148  return true;
149  }
150 
151  template<class T>
153  {
154  return false;
155  }
156 
158  {
159  Superclass::GenerateOutputInformation();
160  InputPixelType dummy;
161  if (!this->PixelIsSingle(dummy))
162  {
163  this->GetOutput()->SetNumberOfComponentsPerPixel(2 * this->GetInput()->GetNumberOfComponentsPerPixel());
164  }
165  }
166 
167 private:
168  ComplexToVectorImageCastFilter(const Self&) = delete;
169  void operator=(const Self&) = delete;
170 
171 };
172 
173 } // end namespace otb
174 
175 
176 #endif
SingleComplexToVector< TInput, TOutput > FunctorType
Transform a complex image into a 2 channels vector image. The first channel is the real part...
bool PixelIsSingle(const itk::VariableLengthVector< T > &)
VectorComplexToVector< itk::VariableLengthVector< TInput >, TOutput > FunctorType
itk::VariableLengthVector< ValueType > TestType
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, typename Functor::ComplexToVector< typename TInputImage::PixelType, typename TOutputImage::PixelType >::FunctorType > Superclass