OTB  9.0.0
Orfeo Toolbox
otbArrayTraits.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 otbArrayTraits_h
22 #define otbArrayTraits_h
23 
24 #include "itkDefaultConvertPixelTraits.h"
25 #include "itkVariableLengthVector.h"
26 #include "itkFixedArray.h"
27 
28 namespace otb
29 {
30 namespace mpl
31 {
32 
33 /*===============================[ otb::is_array<> ]=========================*/
34 namespace internals
35 {
36 
46 template <typename T, unsigned int N>
47 constexpr std::true_type is_array_f(itk::FixedArray<T, N> const*);
48 
52 template <typename... T>
53 constexpr std::false_type is_array_f(...);
54 
55 static_assert(decltype(internals::is_array_f(std::declval<itk::FixedArray<int, 1>*>()))::value, "it::FixedArray should be matched");
56 } // internals namespace
57 
75 template <typename T>
76 struct is_array
77 : decltype(internals::is_array_f(std::declval<T*>()))
78 {};
79 
83 template <typename T>
84 struct is_array<itk::VariableLengthVector<T>>
85 : std::true_type
86 {};
87 
92 template <typename TExpr1, typename TExpr2, typename TBinaryOp>
93 struct is_array<itk::VariableLengthVectorExpression<TExpr1, TExpr2,TBinaryOp>>
94 : std::true_type
95 {};
96 
97 
113 template <typename T>
115 
116 // static_assert(decltype(internals::is_array_f(std::declval<itk::RGBAPixel<int>*>()))::value, "");
117 
118 // static_assert(is_array_v<itk::RGBAPixel<double>>, "");
119 static_assert(is_array_v<itk::FixedArray<double, 42>>, "");
120 static_assert(is_array_v<itk::FixedArray<std::complex<double>, 42>>, "");
121 static_assert(is_array_v<itk::VariableLengthVector<double>>, "");
122 static_assert(is_array_v<itk::VariableLengthVector<std::complex<double>>>, "");
123 
124 /*===============================[ GetNumberOfComponents ]===================*/
125 namespace internals
126 {
127 
144 template <typename PixelType>
146 {
147  static unsigned int For(PixelType const& pix)
148  {
149  return itk::DefaultConvertPixelTraits<std::remove_const_t<PixelType>>::GetNumberOfComponents(pix);
150  }
151 };
153 
157 template <typename RealType>
158 struct NumberOfComponents<itk::VariableLengthVector<RealType>>
159 {
160  // ITK definition of
161  // DefaultConvertPixelTraits<VLV>::GetNumberOfComponents() takes the
162  // parameter by value, and thus create a new VLV by copy.
163  // This is too expensive! Let's work around it.
164  static unsigned int For(itk::VariableLengthVector<RealType> const& pix)
165  {
166  return pix.GetSize();
167  }
168 };
170 
174 template <typename T>
175 struct NumberOfComponents<std::complex<T>>
176 {
177  static constexpr unsigned int For(std::complex<T> const&) noexcept
178  {
179  return 2;
180  }
181 };
182 
187 template <typename T>
188 struct NumberOfComponents<T const>
189 {
190  static unsigned int For(T const& pix)
191  {
192  return NumberOfComponents<T>::For(pix);
193  }
194 };
195 } // internals namespace
197 
213 template <typename PixelType>
214 inline
215 unsigned int GetNumberOfComponents(PixelType const& pix)
216 {
218 }
219 
220 } // otb::mpl namespace
221 } // otb namespace
222 
223 #endif // otbArrayTraits_h
otb::mpl::internals::NumberOfComponents< T const >::For
static unsigned int For(T const &pix)
Definition: otbArrayTraits.h:190
otb::mpl::internals::is_array_f
constexpr std::true_type is_array_f(itk::FixedArray< T, N > const *)
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::mpl::is_array
Definition: otbArrayTraits.h:76
otb::mpl::internals::NumberOfComponents< itk::VariableLengthVector< RealType > >::For
static unsigned int For(itk::VariableLengthVector< RealType > const &pix)
Definition: otbArrayTraits.h:164
otb::mpl::internals::NumberOfComponents::For
static unsigned int For(PixelType const &pix)
Definition: otbArrayTraits.h:147
otb::mpl::GetNumberOfComponents
unsigned int GetNumberOfComponents(PixelType const &pix)
Definition: otbArrayTraits.h:215
otb::mpl::is_array_v
constexpr bool is_array_v
Definition: otbArrayTraits.h:114
itk
Definition: otbNoDataHelper.h:31
otb::mpl::internals::NumberOfComponents< std::complex< T > >::For
static constexpr unsigned int For(std::complex< T > const &) noexcept
Definition: otbArrayTraits.h:177
otb::mpl::internals::NumberOfComponents
Definition: otbArrayTraits.h:145