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#include "itkPrintHelper.h"
26
27namespace itk::Function
28{
43template <typename TScalar, typename TRGBPixel>
45{
46public:
47 ITK_DISALLOW_COPY_AND_MOVE(ColormapFunction);
48
53
55 itkOverrideGetNameOfClassMacro(ColormapFunction);
56
57 using RGBPixelType = TRGBPixel;
58 using RGBComponentType = typename TRGBPixel::ComponentType;
59 using ScalarType = TScalar;
61
62 itkSetMacro(MinimumRGBComponentValue, RGBComponentType);
63 itkGetConstMacro(MinimumRGBComponentValue, RGBComponentType);
64
65 itkSetMacro(MaximumRGBComponentValue, RGBComponentType);
66 itkGetConstMacro(MaximumRGBComponentValue, RGBComponentType);
67
68 itkSetMacro(MinimumInputValue, ScalarType);
69 itkGetConstMacro(MinimumInputValue, ScalarType);
70
71 itkSetMacro(MaximumInputValue, ScalarType);
72 itkGetConstMacro(MaximumInputValue, ScalarType);
73
74 virtual RGBPixelType
75 operator()(const ScalarType &) const = 0;
76
77protected:
84
85 ~ColormapFunction() override = default;
86
92 {
93 auto maxInputValue = static_cast<RealType>(this->m_MaximumInputValue);
94 auto minInputValue = static_cast<RealType>(this->m_MinimumInputValue);
95
96 auto d = static_cast<RealType>(maxInputValue - minInputValue);
97 RealType value = (static_cast<RealType>(v) - static_cast<RealType>(minInputValue)) / d;
98 value = std::clamp(value, 0.0, 1.0);
99 return value;
100 }
101
107 {
109 const RGBComponentType rescaled = static_cast<RGBComponentType>(d * v) + this->m_MinimumRGBComponentValue;
110
111 return rescaled;
112 }
113
114 void
115 PrintSelf(std::ostream & os, Indent indent) const override
116 {
117 Superclass::PrintSelf(os, indent);
118
119 print_helper::PrintNumericTrait(os, indent, "Minimum RGB Component Value", this->GetMinimumRGBComponentValue());
120 print_helper::PrintNumericTrait(os, indent, "Maximum RGB Component Value", this->GetMaximumRGBComponentValue());
121 print_helper::PrintNumericTrait(os, indent, "Minimum Input Value", this->GetMinimumInputValue());
122 print_helper::PrintNumericTrait(os, indent, "Maximum Input Value", this->GetMaximumInputValue());
123 }
124
125private:
128
131};
132} // namespace itk::Function
133
134#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.
void PrintNumericTrait(std::ostream &os, const Indent &indent, const char *name, const T &value)
Print "<name>: <value>\n" indented, matching ITK's PrintSelf style.