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