OTB  9.0.0
Orfeo Toolbox
otbReliefColormapFunctor.hxx
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 otbReliefColormapFunctor_hxx
22 #define otbReliefColormapFunctor_hxx
23 
25 
26 namespace otb
27 {
28 
29 namespace Functor
30 {
31 
32 template <class TScalar, class TRGBPixel>
34 {
35 
36  float m_Borders[] = {0.0f, 0.00001f, 0.2f, 0.43f, 0.71f, 1.0f};
37  float m_RedValues[] = {0.75f, 0.64f, 0.47f, 0.89f, 0.58f, 1.0f};
38  float m_GreenValues[] = {0.91f, 0.84f, 0.76f, 0.90f, 0.32f, 1.0f};
39  float m_BlueValues[] = {0.96f, 0.59f, 0.40f, 0.57f, 0.00f, 1.0f};
40 
41  // Map the input scalar between [0, 1].
42  RealType value = this->RescaleInputValue(v);
43 
44  int i = 1;
45  while (value > m_Borders[i])
46  ++i;
47 
48  float factor = (value - m_Borders[i - 1]) / (m_Borders[i] - m_Borders[i - 1]);
49 
50  // Apply the color mapping.
51  RealType red = m_RedValues[i - 1] + factor * (m_RedValues[i] - m_RedValues[i - 1]);
52 
53  RealType green = m_GreenValues[i - 1] + factor * (m_GreenValues[i] - m_GreenValues[i - 1]);
54 
55  RealType blue = m_BlueValues[i - 1] + factor * (m_BlueValues[i] - m_BlueValues[i - 1]);
56 
57  // Normalize the values
58  red = vnl_math_max(0.0, red);
59  red = vnl_math_min(1.0, red);
60 
61  green = vnl_math_max(0.0, green);
62  green = vnl_math_min(1.0, green);
63 
64  blue = vnl_math_max(0.0, blue);
65  blue = vnl_math_min(1.0, blue);
66 
67  // Set the rgb components after rescaling the values.
68  RGBPixelType pixel;
69 
70  pixel[0] = this->RescaleRGBComponentValue(red);
71  pixel[1] = this->RescaleRGBComponentValue(green);
72  pixel[2] = this->RescaleRGBComponentValue(blue);
73 
74  return pixel;
75 }
76 
77 } // end namespace Functor
78 
79 } // end namespace otb
80 
81 #endif
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::ReliefColormapFunctor::operator()
RGBPixelType operator()(const TScalar &) const override
Definition: otbReliefColormapFunctor.hxx:33
otb::Functor::ReliefColormapFunctor::RealType
Superclass::RealType RealType
Definition: otbReliefColormapFunctor.h:59
otbReliefColormapFunctor.h
otb::Functor::ReliefColormapFunctor::RGBPixelType
Superclass::RGBPixelType RGBPixelType
Definition: otbReliefColormapFunctor.h:55