ITK  5.3.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  * http://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  itkTypeMacro(ColormapFunction, Object);
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);
98 
99  auto d = static_cast<RealType>(maxInputValue - minInputValue);
100  RealType value = (static_cast<RealType>(v) - static_cast<RealType>(minInputValue)) / d;
101 
102  value = std::max(0.0, value);
103  value = std::min(1.0, value);
104  return value;
105  }
106 
112  {
113  auto d = static_cast<RealType>(m_MaximumRGBComponentValue - m_MinimumRGBComponentValue);
114  const RGBComponentType rescaled = static_cast<RGBComponentType>(d * v) + this->m_MinimumRGBComponentValue;
116 
117  return rescaled;
118  }
119 
120  void
121  PrintSelf(std::ostream & os, Indent indent) const override
122  {
123  Superclass::PrintSelf(os, indent);
124 
125  os << indent << "Minimum RGB Component Value: "
127  << std::endl;
128  os << indent << "Maximum RGB Component Value: "
130  << std::endl;
131  os << indent << "Minimum Input Value: "
132  << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMinimumInputValue()) << std::endl;
133  os << indent << "Maximum Input Value: "
134  << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMaximumInputValue()) << std::endl;
135  }
136 
137 private:
140 
143 };
144 } // end namespace Function
145 } // end namespace itk
146 
147 #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:172
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:121
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:141
itk::Function::ColormapFunction::m_MaximumInputValue
ScalarType m_MaximumInputValue
Definition: itkColormapFunction.h:139
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::Function::ColormapFunction::RGBPixelType
TRGBPixel RGBPixelType
Definition: itkColormapFunction.h:58
itk::NumericTraits::PrintType
T PrintType
Definition: itkNumericTraits.h:68
itk::Function::ColormapFunction::GetMinimumRGBComponentValue
virtual RGBComponentType GetMinimumRGBComponentValue() const
itk::Function::ColormapFunction::RescaleRGBComponentValue
RGBComponentType RescaleRGBComponentValue(RealType v) const
Definition: itkColormapFunction.h:111
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:58
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:167
itkObject.h
itk::Function::ColormapFunction::m_MaximumRGBComponentValue
RGBComponentType m_MaximumRGBComponentValue
Definition: itkColormapFunction.h:142
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:62
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:138