OTB  9.0.0
Orfeo Toolbox
otbDefaultConvertPixelTraits.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 otbDefaultConvertPixelTraits_h
22 #define otbDefaultConvertPixelTraits_h
23 
24 #include "itkDefaultConvertPixelTraits.h"
25 #include "OTBImageBaseExport.h"
26 
27 namespace otb
28 {
29 
30 
31 template <typename PixelType>
32 class OTBImageBase_EXPORT_TEMPLATE DefaultConvertPixelTraits : public itk::DefaultConvertPixelTraits<PixelType>
33 {
34 public:
35  typedef itk::DefaultConvertPixelTraits<PixelType> SuperClass;
36  using typename SuperClass::ComponentType;
37 
38  using SuperClass::SetNthComponent;
39 
40  static void SetNthComponent(int, PixelType& pixel, const PixelType& v)
41  {
42  pixel = v;
43  }
44 };
45 
46 template <typename T>
47 class DefaultConvertPixelTraits<::std::complex<T>> : public itk::DefaultConvertPixelTraits<::std::complex<T>>
48 {
49 public:
50  typedef itk::DefaultConvertPixelTraits<::std::complex<T>> SuperClass;
51  using typename SuperClass::TargetType;
52  using typename SuperClass::ComponentType;
53 
54  using SuperClass::SetNthComponent;
55 
56  static void SetNthComponent(int, TargetType& pixel, const TargetType& v)
57  {
58  pixel = v;
59  }
60 
61  static TargetType GetNthComponent(int, const TargetType& pixel)
62  {
63  return pixel;
64  }
65 
66  static ComponentType GetScalarValue(const TargetType& pixel)
67  {
68  /*
69  * This seems to be dead code, since the complex to scalar
70  * conversion is done by ConvertPixelBuffer
71  *
72  * Historically, it was returning std::norm, which causes
73  * compilation error on MacOSX 10.9.
74  * Now returns the equivalent implementation of std::norm.
75  */
76  return static_cast<ComponentType>(pixel.real() * pixel.real() + pixel.imag() * pixel.imag());
77  }
78 };
79 
80 } // end namespace
81 #endif
otb::DefaultConvertPixelTraits<::std::complex< T > >::GetNthComponent
static TargetType GetNthComponent(int, const TargetType &pixel)
Definition: otbDefaultConvertPixelTraits.h:61
otb::DefaultConvertPixelTraits::SetNthComponent
static void SetNthComponent(int, PixelType &pixel, const PixelType &v)
Definition: otbDefaultConvertPixelTraits.h:40
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::DefaultConvertPixelTraits<::std::complex< T > >::GetScalarValue
static ComponentType GetScalarValue(const TargetType &pixel)
Definition: otbDefaultConvertPixelTraits.h:66
otb::DefaultConvertPixelTraits<::std::complex< T > >::SetNthComponent
static void SetNthComponent(int, TargetType &pixel, const TargetType &v)
Definition: otbDefaultConvertPixelTraits.h:56
otb::DefaultConvertPixelTraits<::std::complex< T > >::SuperClass
itk::DefaultConvertPixelTraits<::std::complex< T > > SuperClass
Definition: otbDefaultConvertPixelTraits.h:50
otb::DefaultConvertPixelTraits::SuperClass
itk::DefaultConvertPixelTraits< PixelType > SuperClass
Definition: otbDefaultConvertPixelTraits.h:35
otb::DefaultConvertPixelTraits
Definition: otbDefaultConvertPixelTraits.h:32