OTB  10.0.0
Orfeo Toolbox
otbAffineFunctor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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
This functor performs a linear transform of its input.
void SetA(TScale value)
Accessors.
bool operator==(const AffineFunctor &other) const
bool operator!=(const AffineFunctor &other) const
TOutput operator()(const TInput &x) const
virtual ~AffineFunctor()
Constructor.
void SetB(TOutput value)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.