ITK  5.1.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 {
45 template <typename TScalar, typename TRGBPixel>
46 class ColormapFunction : public Object
47 {
48 public:
49  ITK_DISALLOW_COPY_AND_ASSIGN(ColormapFunction);
50 
52  using Superclass = Object;
55 
57  itkTypeMacro(ColormapFunction, Object);
58 
59  using RGBPixelType = TRGBPixel;
60  using RGBComponentType = typename TRGBPixel::ComponentType;
61  using ScalarType = TScalar;
63 
64  itkSetMacro(MinimumRGBComponentValue, RGBComponentType);
65  itkGetConstMacro(MinimumRGBComponentValue, RGBComponentType);
66 
67  itkSetMacro(MaximumRGBComponentValue, RGBComponentType);
68  itkGetConstMacro(MaximumRGBComponentValue, RGBComponentType);
69 
70  itkSetMacro(MinimumInputValue, ScalarType);
71  itkGetConstMacro(MinimumInputValue, ScalarType);
72 
73  itkSetMacro(MaximumInputValue, ScalarType);
74  itkGetConstMacro(MaximumInputValue, ScalarType);
75 
76  virtual bool
78  {
79  return false;
80  }
81 
82  virtual bool
83  operator==(const ColormapFunction & other) const
84  {
85  return !(*this != other);
86  }
87 
88  virtual RGBPixelType
89  operator()(const ScalarType &) const = 0;
90 
91 protected:
93  {
98  }
99 
100  ~ColormapFunction() override = default;
101 
105  RealType
107  {
108  auto maxInputValue = static_cast<RealType>(this->m_MaximumInputValue);
109  auto minInputValue = static_cast<RealType>(this->m_MinimumInputValue);
111 
112  auto d = static_cast<RealType>(maxInputValue - minInputValue);
113  RealType value = (static_cast<RealType>(v) - static_cast<RealType>(minInputValue)) / d;
114 
115  value = std::max(0.0, value);
116  value = std::min(1.0, value);
117  return value;
118  }
119 
125  {
126  auto d = static_cast<RealType>(m_MaximumRGBComponentValue - m_MinimumRGBComponentValue);
127  const RGBComponentType rescaled = static_cast<RGBComponentType>(d * v) + this->m_MinimumRGBComponentValue;
129 
130  return rescaled;
131  }
132 
133  void
134  PrintSelf(std::ostream & os, Indent indent) const override
135  {
136  Superclass::PrintSelf(os, indent);
137 
138  os << indent << "Minimum RGB Component Value: "
140  << std::endl;
141  os << indent << "Maximum RGB Component Value: "
143  << std::endl;
144  os << indent << "Minimum Input Value: "
145  << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMinimumInputValue()) << std::endl;
146  os << indent << "Maximum Input Value: "
147  << static_cast<typename NumericTraits<ScalarType>::PrintType>(this->GetMaximumInputValue()) << std::endl;
148  }
149 
150 private:
153 
156 };
157 } // end namespace Function
158 } // end namespace itk
159 
160 #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:77
itk::Function::ColormapFunction::RealType
typename NumericTraits< ScalarType >::RealType RealType
Definition: itkColormapFunction.h:62
itk::Function::ColormapFunction::GetMaximumInputValue
virtual ScalarType GetMaximumInputValue() const
itk::Function::ColormapFunction::RescaleInputValue
RealType RescaleInputValue(ScalarType v) const
Definition: itkColormapFunction.h:106
itk::Function::ColormapFunction::operator()
virtual RGBPixelType operator()(const ScalarType &) const =0
itk::Function::ColormapFunction::ScalarType
TScalar ScalarType
Definition: itkColormapFunction.h:61
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:60
itk::Function::ColormapFunction::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkColormapFunction.h:134
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:46
itk::Function::ColormapFunction::m_MinimumRGBComponentValue
RGBComponentType m_MinimumRGBComponentValue
Definition: itkColormapFunction.h:154
itk::Function::ColormapFunction::m_MaximumInputValue
ScalarType m_MaximumInputValue
Definition: itkColormapFunction.h:152
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::Function::ColormapFunction::RGBPixelType
TRGBPixel RGBPixelType
Definition: itkColormapFunction.h:59
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:124
itk::Function::ColormapFunction::ColormapFunction
ColormapFunction()
Definition: itkColormapFunction.h:92
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:155
itk::Function::ColormapFunction::operator==
virtual bool operator==(const ColormapFunction &other) const
Definition: itkColormapFunction.h:83
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60
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:151