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 bool
77  {
78  return false;
79  }
80 
81  virtual bool
82  operator==(const ColormapFunction & other) const
83  {
84  return !(*this != other);
85  }
86 
87  virtual RGBPixelType
88  operator()(const ScalarType &) const = 0;
89 
90 protected:
92  {
97  }
98 
99  ~ColormapFunction() override = default;
100 
104  RealType
106  {
107  auto maxInputValue = static_cast<RealType>(this->m_MaximumInputValue);
108  auto minInputValue = static_cast<RealType>(this->m_MinimumInputValue);
110 
111  auto d = static_cast<RealType>(maxInputValue - minInputValue);
112  RealType value = (static_cast<RealType>(v) - static_cast<RealType>(minInputValue)) / d;
113 
114  value = std::max(0.0, value);
115  value = std::min(1.0, value);
116  return value;
117  }
118 
124  {
125  auto d = static_cast<RealType>(m_MaximumRGBComponentValue - m_MinimumRGBComponentValue);
126  const RGBComponentType rescaled = static_cast<RGBComponentType>(d * v) + this->m_MinimumRGBComponentValue;
128 
129  return rescaled;
130  }
131 
132  void
133  PrintSelf(std::ostream & os, Indent indent) const override
134  {
135  Superclass::PrintSelf(os, indent);
136 
137  os << indent << "Minimum RGB Component Value: "
139  << std::endl;
140  os << indent << "Maximum RGB Component Value: "
142  << std::endl;
143  os << indent << "Minimum Input Value: "
144  << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMinimumInputValue()) << std::endl;
145  os << indent << "Maximum Input Value: "
146  << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMaximumInputValue()) << std::endl;
147  }
148 
149 private:
152 
155 };
156 } // end namespace Function
157 } // end namespace itk
158 
159 #endif
itkObjectFactory.h
itk::Function::ColormapFunction::GetMaximumRGBComponentValue
virtual RGBComponentType GetMaximumRGBComponentValue() const
itkRGBPixel.h
itk::Function::ColormapFunction::operator!=
virtual bool operator!=(const ColormapFunction &) const
Definition: itkColormapFunction.h:76
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:105
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:133
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:153
itk::Function::ColormapFunction::m_MaximumInputValue
ScalarType m_MaximumInputValue
Definition: itkColormapFunction.h:151
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:123
itk::Function::ColormapFunction::ColormapFunction
ColormapFunction()
Definition: itkColormapFunction.h:91
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:154
itk::Function::ColormapFunction::operator==
virtual bool operator==(const ColormapFunction &other) const
Definition: itkColormapFunction.h:82
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:150