ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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::Function
27{
42template <typename TScalar, typename TRGBPixel>
44{
45public:
46 ITK_DISALLOW_COPY_AND_MOVE(ColormapFunction);
47
52
54 itkOverrideGetNameOfClassMacro(ColormapFunction);
55
56 using RGBPixelType = TRGBPixel;
57 using RGBComponentType = typename TRGBPixel::ComponentType;
58 using ScalarType = TScalar;
60
61 itkSetMacro(MinimumRGBComponentValue, RGBComponentType);
62 itkGetConstMacro(MinimumRGBComponentValue, RGBComponentType);
63
64 itkSetMacro(MaximumRGBComponentValue, RGBComponentType);
65 itkGetConstMacro(MaximumRGBComponentValue, RGBComponentType);
66
67 itkSetMacro(MinimumInputValue, ScalarType);
68 itkGetConstMacro(MinimumInputValue, ScalarType);
69
70 itkSetMacro(MaximumInputValue, ScalarType);
71 itkGetConstMacro(MaximumInputValue, ScalarType);
72
73 virtual RGBPixelType
74 operator()(const ScalarType &) const = 0;
75
76protected:
83
84 ~ColormapFunction() override = default;
85
91 {
92 auto maxInputValue = static_cast<RealType>(this->m_MaximumInputValue);
93 auto minInputValue = static_cast<RealType>(this->m_MinimumInputValue);
94
95 auto d = static_cast<RealType>(maxInputValue - minInputValue);
96 RealType value = (static_cast<RealType>(v) - static_cast<RealType>(minInputValue)) / d;
97 value = std::clamp(value, 0.0, 1.0);
98 return value;
99 }
100
106 {
108 const RGBComponentType rescaled = static_cast<RGBComponentType>(d * v) + this->m_MinimumRGBComponentValue;
109
110 return rescaled;
111 }
112
113 void
114 PrintSelf(std::ostream & os, Indent indent) const override
115 {
116 Superclass::PrintSelf(os, indent);
117
118 os << indent << "Minimum RGB Component Value: "
120 << std::endl;
121 os << indent << "Maximum RGB Component Value: "
123 << std::endl;
124 os << indent << "Minimum Input Value: "
125 << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMinimumInputValue()) << std::endl;
126 os << indent << "Maximum Input Value: "
127 << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMaximumInputValue()) << std::endl;
128 }
129
130private:
133
136};
137} // namespace itk::Function
138
139#endif
void PrintSelf(std::ostream &os, Indent indent) const override
RealType RescaleInputValue(ScalarType v) const
RGBComponentType RescaleRGBComponentValue(RealType v) const
~ColormapFunction() override=default
SmartPointer< const Self > ConstPointer
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
Define additional traits for native types such as int or float.
void PrintSelf(std::ostream &os, Indent indent) const override
Implements transparent reference counting.