ITK  5.4.0
Insight Toolkit
itkColormapFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkColormapFunction_h
19 #define itkColormapFunction_h
20 
21 #include "itkObject.h"
22 #include "itkObjectFactory.h"
23 #include "itkNumericTraits.h"
24 #include "itkRGBPixel.h"
25 
26 namespace itk
27 {
28 namespace Function
29 {
44 template <typename TScalar, typename TRGBPixel>
45 class ColormapFunction : public Object
46 {
47 public:
48  ITK_DISALLOW_COPY_AND_MOVE(ColormapFunction);
49 
51  using Superclass = Object;
54 
56  itkOverrideGetNameOfClassMacro(ColormapFunction);
57 
58  using RGBPixelType = TRGBPixel;
59  using RGBComponentType = typename TRGBPixel::ComponentType;
60  using ScalarType = TScalar;
62 
63  itkSetMacro(MinimumRGBComponentValue, RGBComponentType);
64  itkGetConstMacro(MinimumRGBComponentValue, RGBComponentType);
65 
66  itkSetMacro(MaximumRGBComponentValue, RGBComponentType);
67  itkGetConstMacro(MaximumRGBComponentValue, RGBComponentType);
68 
69  itkSetMacro(MinimumInputValue, ScalarType);
70  itkGetConstMacro(MinimumInputValue, ScalarType);
71 
72  itkSetMacro(MaximumInputValue, ScalarType);
73  itkGetConstMacro(MaximumInputValue, ScalarType);
74 
75  virtual RGBPixelType
76  operator()(const ScalarType &) const = 0;
77 
78 protected:
80  {
85  }
86 
87  ~ColormapFunction() override = default;
88 
92  RealType
94  {
95  auto maxInputValue = static_cast<RealType>(this->m_MaximumInputValue);
96  auto minInputValue = static_cast<RealType>(this->m_MinimumInputValue);
99  auto d = static_cast<RealType>(maxInputValue - minInputValue);
100  RealType value = (static_cast<RealType>(v) - static_cast<RealType>(minInputValue)) / d;
101  value = std::clamp(value, 0.0, 1.0);
102  return value;
103  }
104 
110  {
111  auto d = static_cast<RealType>(m_MaximumRGBComponentValue - m_MinimumRGBComponentValue);
112  const RGBComponentType rescaled = static_cast<RGBComponentType>(d * v) + this->m_MinimumRGBComponentValue;
115  return rescaled;
116  }
117 
118  void
119  PrintSelf(std::ostream & os, Indent indent) const override
120  {
121  Superclass::PrintSelf(os, indent);
122 
123  os << indent << "Minimum RGB Component Value: "
125  << std::endl;
126  os << indent << "Maximum RGB Component Value: "
128  << std::endl;
129  os << indent << "Minimum Input Value: "
130  << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMinimumInputValue()) << std::endl;
131  os << indent << "Maximum Input Value: "
132  << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMaximumInputValue()) << std::endl;
133  }
134 
135 private:
138 
141 };
142 } // end namespace Function
143 } // end namespace itk
144 
145 #endif
itkObjectFactory.h
itk::Function::ColormapFunction::GetMaximumRGBComponentValue
virtual RGBComponentType GetMaximumRGBComponentValue() const
itkRGBPixel.h
itk::Function::ColormapFunction::RealType
typename NumericTraits< ScalarType >::RealType RealType
Definition: itkColormapFunction.h:61
itk::Function::ColormapFunction::GetMaximumInputValue
virtual ScalarType GetMaximumInputValue() const
itk::Function::ColormapFunction::RescaleInputValue
RealType RescaleInputValue(ScalarType v) const
Definition: itkColormapFunction.h:93
itk::Function::ColormapFunction::operator()
virtual RGBPixelType operator()(const ScalarType &) const =0
itk::Function::ColormapFunction::ScalarType
TScalar ScalarType
Definition: itkColormapFunction.h:60
itk::Function::ColormapFunction::~ColormapFunction
~ColormapFunction() override=default
itk::NumericTraits::min
static constexpr T min(const T &)
Definition: itkNumericTraits.h:173
itk::Function::ColormapFunction::RGBComponentType
typename TRGBPixel::ComponentType RGBComponentType
Definition: itkColormapFunction.h:59
itk::Function::ColormapFunction::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkColormapFunction.h:119
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Function::ColormapFunction
Function object which maps a scalar value into an RGB colormap value.
Definition: itkColormapFunction.h:45
itk::Function::ColormapFunction::m_MinimumRGBComponentValue
RGBComponentType m_MinimumRGBComponentValue
Definition: itkColormapFunction.h:139
itk::Function::ColormapFunction::m_MaximumInputValue
ScalarType m_MaximumInputValue
Definition: itkColormapFunction.h:137
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::Function::ColormapFunction::RGBPixelType
TRGBPixel RGBPixelType
Definition: itkColormapFunction.h:58
itk::NumericTraits::PrintType
T PrintType
Definition: itkNumericTraits.h:69
itk::Function::ColormapFunction::GetMinimumRGBComponentValue
virtual RGBComponentType GetMinimumRGBComponentValue() const
itk::Function::ColormapFunction::RescaleRGBComponentValue
RGBComponentType RescaleRGBComponentValue(RealType v) const
Definition: itkColormapFunction.h:109
itk::Function::ColormapFunction::ColormapFunction
ColormapFunction()
Definition: itkColormapFunction.h:79
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:59
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:168
itkObject.h
itk::Function::ColormapFunction::m_MaximumRGBComponentValue
RGBComponentType m_MaximumRGBComponentValue
Definition: itkColormapFunction.h:140
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itkNumericTraits.h
itk::Function::ColormapFunction::GetMinimumInputValue
virtual ScalarType GetMinimumInputValue() const
itk::Object::Object
Object()
itk::Object::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::Function::ColormapFunction::m_MinimumInputValue
ScalarType m_MinimumInputValue
Definition: itkColormapFunction.h:136