OTB  9.0.0
Orfeo Toolbox
otbAffineFunctor.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 
22 #ifndef otbAffineFunctor_h
23 #define otbAffineFunctor_h
24 
25 namespace otb
26 {
27 namespace Functor
28 {
42 template <class TInput, class TOutput, class TScale = double>
44 {
45 public:
47  AffineFunctor() : m_A(0.), m_B(0.)
48  {
49  }
50 
52  virtual ~AffineFunctor()
53  {
54  }
55 
57  void SetA(TScale value)
58  {
59  m_A = value;
60  }
61  TScale GetA()
62  {
63  return m_A;
64  }
65  void SetB(TOutput value)
66  {
67  m_B = value;
68  }
69  TOutput GetB()
70  {
71  return m_B;
72  }
73 
74  bool operator!=(const AffineFunctor& other) const
75  {
76  return ((m_A != other.GetA()) || (m_B != other.GetB()));
77  }
78 
79  bool operator==(const AffineFunctor& other) const
80  {
81  return ((m_A == other.GetA()) && (m_B == other.GetB()));
82  }
83 
84  // main computation method
85  inline TOutput operator()(const TInput& x) const
86  {
87  return (m_B + static_cast<TOutput>(m_A * x));
88  }
89 
90 private:
91  TScale m_A;
92  TOutput m_B;
93 };
94 } // End namespace Functor
95 } // End namespace otb
96 
97 #endif
otb::Functor::AffineFunctor::m_B
TOutput m_B
Definition: otbAffineFunctor.h:92
otb::Functor::AffineFunctor::SetB
void SetB(TOutput value)
Definition: otbAffineFunctor.h:65
otb::Functor::AffineFunctor::operator!=
bool operator!=(const AffineFunctor &other) const
Definition: otbAffineFunctor.h:74
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::AffineFunctor
This functor performs a linear transform of its input.
Definition: otbAffineFunctor.h:43
otb::Functor::AffineFunctor::AffineFunctor
AffineFunctor()
Constructor.
Definition: otbAffineFunctor.h:47
otb::Functor::AffineFunctor::GetA
TScale GetA()
Definition: otbAffineFunctor.h:61
otb::Functor::AffineFunctor::operator==
bool operator==(const AffineFunctor &other) const
Definition: otbAffineFunctor.h:79
otb::Functor::AffineFunctor::m_A
TScale m_A
Definition: otbAffineFunctor.h:91
otb::Functor::AffineFunctor::operator()
TOutput operator()(const TInput &x) const
Definition: otbAffineFunctor.h:85
otb::Functor::AffineFunctor::~AffineFunctor
virtual ~AffineFunctor()
Constructor.
Definition: otbAffineFunctor.h:52
otb::Functor::AffineFunctor::SetA
void SetA(TScale value)
Accessors.
Definition: otbAffineFunctor.h:57
otb::Functor::AffineFunctor::GetB
TOutput GetB()
Definition: otbAffineFunctor.h:69