ITK  4.13.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 
51  typedef Object Superclass;
54 
56  itkTypeMacro(ColormapFunction, Object);
57 
58  typedef TRGBPixel RGBPixelType;
59  typedef typename TRGBPixel::ComponentType RGBComponentType;
60  typedef TScalar ScalarType;
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 operator!=(const ColormapFunction &) const
76  {
77  return false;
78  }
79 
80  virtual bool operator==(const ColormapFunction & other) const
81  {
82  return !( *this != other );
83  }
84 
85  virtual RGBPixelType operator()(const ScalarType &) const = 0;
86 
87 protected:
89  {
94  }
95 
96  ~ColormapFunction() ITK_OVERRIDE {}
97 
102  {
103  RealType maxInputValue =
104  static_cast< RealType >( this->m_MaximumInputValue );
105  RealType minInputValue =
106  static_cast< RealType >( this->m_MinimumInputValue );
108 
109  RealType d = static_cast< RealType >( maxInputValue - minInputValue );
110  RealType value = ( static_cast< RealType >( v ) -
111  static_cast< RealType >( minInputValue ) ) / d;
112 
113  value = std::max(0.0, value);
114  value = std::min(1.0, value);
115  return value;
116  }
117 
122  {
123  RealType d = static_cast< RealType >( m_MaximumRGBComponentValue -
125  const RGBComponentType rescaled = static_cast< RGBComponentType >(
126  d * v ) + this->m_MinimumRGBComponentValue;
128 
129  return rescaled;
130  }
131 
132  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE
133  {
134  Superclass::PrintSelf(os, indent);
135 
136  os << indent << "Minimum RGB Component Value: "
137  << static_cast< typename NumericTraits< RGBComponentType >::PrintType >(
138  this->GetMinimumRGBComponentValue() ) << std::endl;
139  os << indent << "Maximum RGB Component Value: "
140  << static_cast< typename NumericTraits< RGBComponentType >::PrintType >(
141  this->GetMaximumRGBComponentValue() ) << std::endl;
142  os << indent << "Minimum Input Value: "
143  << static_cast< typename NumericTraits< ScalarType >::PrintType >(
144  this->GetMinimumInputValue() ) << std::endl;
145  os << indent << "Maximum Input Value: "
146  << static_cast< typename NumericTraits< ScalarType >::PrintType >(
147  this->GetMaximumInputValue() ) << std::endl;
148  }
149 
150 private:
151  ITK_DISALLOW_COPY_AND_ASSIGN(ColormapFunction);
152 
155 
158 };
159 } // end namespace functor
160 } // end namespace itk
161 
162 #endif
virtual RGBComponentType GetMinimumRGBComponentValue() const
virtual RGBComponentType GetMaximumRGBComponentValue() const
virtual ScalarType GetMinimumInputValue() const
virtual bool operator!=(const ColormapFunction &) const
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.
static ITK_CONSTEXPR_FUNC T max(const T &)
RGBComponentType RescaleRGBComponentValue(RealType v) const
NumericTraits< ScalarType >::RealType RealType
static ITK_CONSTEXPR_FUNC T min(const T &)
SmartPointer< const Self > ConstPointer
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void PrintSelf(std::ostream &os, Indent indent) const override
virtual void PrintSelf(std::ostream &os, Indent indent) const override
TRGBPixel::ComponentType RGBComponentType
virtual ScalarType GetMaximumInputValue() const
Define additional traits for native types such as int or float.
Base class for most ITK classes.
Definition: itkObject.h:59
RealType RescaleInputValue(ScalarType v) const