ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkColormapFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 >
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 operator!=(const ColormapFunction &) const
77  {
78  return false;
79  }
80 
81  virtual bool operator==(const ColormapFunction & other) const
82  {
83  return !( *this != other );
84  }
85 
86  virtual RGBPixelType operator()(const ScalarType &) const = 0;
87 
88 protected:
90  {
95  }
96 
97  ~ColormapFunction() override = default;
98 
103  {
104  auto maxInputValue = static_cast< RealType >( this->m_MaximumInputValue );
105  auto minInputValue = static_cast< RealType >( this->m_MinimumInputValue );
107 
108  auto d = static_cast< RealType >( maxInputValue - minInputValue );
109  RealType value = ( static_cast< RealType >( v ) -
110  static_cast< RealType >( minInputValue ) ) / d;
111 
112  value = std::max(0.0, value);
113  value = std::min(1.0, value);
114  return value;
115  }
116 
121  {
122  auto d = static_cast< RealType >( m_MaximumRGBComponentValue -
124  const RGBComponentType rescaled = static_cast< RGBComponentType >(
125  d * v ) + this->m_MinimumRGBComponentValue;
127 
128  return rescaled;
129  }
130 
131  void PrintSelf(std::ostream & os, Indent indent) const override
132  {
133  Superclass::PrintSelf(os, indent);
134 
135  os << indent << "Minimum RGB Component Value: "
136  << static_cast< typename NumericTraits< RGBComponentType >::PrintType >(
137  this->GetMinimumRGBComponentValue() ) << std::endl;
138  os << indent << "Maximum RGB Component Value: "
139  << static_cast< typename NumericTraits< RGBComponentType >::PrintType >(
140  this->GetMaximumRGBComponentValue() ) << std::endl;
141  os << indent << "Minimum Input Value: "
142  << static_cast< typename NumericTraits< ScalarType >::PrintType >(
143  this->GetMinimumInputValue() ) << std::endl;
144  os << indent << "Maximum Input Value: "
145  << static_cast< typename NumericTraits< ScalarType >::PrintType >(
146  this->GetMaximumInputValue() ) << std::endl;
147  }
148 
149 private:
152 
155 };
156 } // end namespace Function
157 } // end namespace itk
158 
159 #endif
Light weight base class for most itk classes.
virtual RGBComponentType GetMinimumRGBComponentValue() const
virtual RGBComponentType GetMaximumRGBComponentValue() const
Define numeric traits for std::vector.
virtual ScalarType GetMinimumInputValue() const
typename TRGBPixel::ComponentType RGBComponentType
virtual bool operator!=(const ColormapFunction &) const
~ColormapFunction() override=default
virtual bool operator==(const ColormapFunction &other) const
virtual RGBPixelType operator()(const ScalarType &) const =0
Function object which maps a scalar value into an RGB colormap value.
void PrintSelf(std::ostream &os, Indent indent) const override
RGBComponentType RescaleRGBComponentValue(RealType v) const
void PrintSelf(std::ostream &os, Indent indent) const override
typename NumericTraits< ScalarType >::RealType RealType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual ScalarType GetMaximumInputValue() const
Base class for most ITK classes.
Definition: itkObject.h:60
RealType RescaleInputValue(ScalarType v) const