OTB  9.0.0
Orfeo Toolbox
otbUniformAlphaBlendingFunctor.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 otbUniformAlphaBlendingFunctor_h
22 #define otbUniformAlphaBlendingFunctor_h
23 
24 #include "itkMacro.h"
25 #include "itkNumericTraits.h"
26 #include "otbMath.h"
27 
28 namespace otb
29 {
30 namespace Functor
31 {
41 template <class TInputPixel, class TInputPixel2, class TOutputPixel>
43 {
44 public:
45  UniformAlphaBlendingFunctor() : m_Alpha(0.5)
46  {
47  }
49  {
50  }
51 
52  typedef TInputPixel InputPixelType;
53  typedef TInputPixel2 InputPixel2Type;
54  typedef TOutputPixel OutputPixelType;
55  typedef typename OutputPixelType::ValueType OutputInternalPixelType;
56 
57  void SetAlpha(double a)
58  {
59  // Keep alpha between 0 and 1
60  m_Alpha = a < 0.0 ? 0.0 : (a > 1.0 ? 1.0 : a);
61  }
62  double GetAlpha() const
63  {
64  return m_Alpha;
65  }
66 
68  {
69  OutputPixelType resp;
70  resp.Fill(itk::NumericTraits<OutputInternalPixelType>::max());
71  resp.SetRed(static_cast<OutputInternalPixelType>(
72  std::floor(m_Alpha * static_cast<double>(input1.GetRed()) + (1 - m_Alpha) * static_cast<double>(input2.GetRed()) + 0.5)));
73  resp.SetGreen(static_cast<OutputInternalPixelType>(
74  std::floor(m_Alpha * static_cast<double>(input1.GetGreen()) + (1 - m_Alpha) * static_cast<double>(input2.GetGreen()) + 0.5)));
75  resp.SetBlue(static_cast<OutputInternalPixelType>(
76  std::floor(m_Alpha * static_cast<double>(input1.GetBlue()) + (1 - m_Alpha) * static_cast<double>(input2.GetBlue()) + 0.5)));
77  return resp;
78  }
79 
80 protected:
81  double m_Alpha;
82 };
83 }
84 }
85 #endif
otb::Functor::UniformAlphaBlendingFunctor::OutputPixelType
TOutputPixel OutputPixelType
Definition: otbUniformAlphaBlendingFunctor.h:54
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::UniformAlphaBlendingFunctor::GetAlpha
double GetAlpha() const
Definition: otbUniformAlphaBlendingFunctor.h:62
otb::Functor::UniformAlphaBlendingFunctor::InputPixel2Type
TInputPixel2 InputPixel2Type
Definition: otbUniformAlphaBlendingFunctor.h:53
otb::Functor::UniformAlphaBlendingFunctor::operator()
OutputPixelType operator()(InputPixelType input1, InputPixel2Type input2) const
Definition: otbUniformAlphaBlendingFunctor.h:67
otb::Functor::UniformAlphaBlendingFunctor::~UniformAlphaBlendingFunctor
~UniformAlphaBlendingFunctor()
Definition: otbUniformAlphaBlendingFunctor.h:48
otb::Functor::UniformAlphaBlendingFunctor::UniformAlphaBlendingFunctor
UniformAlphaBlendingFunctor()
Definition: otbUniformAlphaBlendingFunctor.h:45
otb::Functor::UniformAlphaBlendingFunctor::OutputInternalPixelType
OutputPixelType::ValueType OutputInternalPixelType
Definition: otbUniformAlphaBlendingFunctor.h:55
otb::Functor::UniformAlphaBlendingFunctor::m_Alpha
double m_Alpha
Definition: otbUniformAlphaBlendingFunctor.h:81
otb::Functor::UniformAlphaBlendingFunctor::SetAlpha
void SetAlpha(double a)
Definition: otbUniformAlphaBlendingFunctor.h:57
otb::Functor::UniformAlphaBlendingFunctor::InputPixelType
TInputPixel InputPixelType
Definition: otbUniformAlphaBlendingFunctor.h:52
otb::Functor::UniformAlphaBlendingFunctor
Implements simple blending For each channel the blending function is as follows:
Definition: otbUniformAlphaBlendingFunctor.h:42