ITK  6.0.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
26namespace itk
27{
28namespace Function
29{
44template <typename TScalar, typename TRGBPixel>
46{
47public:
48 ITK_DISALLOW_COPY_AND_MOVE(ColormapFunction);
49
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
78protected:
80 {
85 }
86
87 ~ColormapFunction() override = default;
88
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 {
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
135private:
138
141};
142} // end namespace Function
143} // end namespace itk
144
145#endif
Function object which maps a scalar value into an RGB colormap value.
void PrintSelf(std::ostream &os, Indent indent) const override
RealType RescaleInputValue(ScalarType v) const
RGBComponentType RescaleRGBComponentValue(RealType v) const
~ColormapFunction() override=default
typename TRGBPixel::ComponentType RGBComponentType
typename NumericTraits< ScalarType >::RealType RealType
virtual RGBComponentType GetMinimumRGBComponentValue() const
virtual ScalarType GetMinimumInputValue() const
virtual RGBComponentType GetMaximumRGBComponentValue() const
virtual ScalarType GetMaximumInputValue() const
virtual RGBPixelType operator()(const ScalarType &) const =0
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Define additional traits for native types such as int or float.
static constexpr T max(const T &)
static constexpr T min(const T &)
Base class for most ITK classes.
Definition: itkObject.h:62
void PrintSelf(std::ostream &os, Indent indent) const override
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....