ITK  4.6.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 
97 
102  {
103  RealType d = static_cast< RealType >( this->m_MaximumInputValue -
104  this->m_MinimumInputValue );
105  RealType value = ( static_cast< RealType >( v ) -
106  static_cast< RealType >( this->m_MinimumInputValue ) ) / d;
108 
109  value = vnl_math_max(0.0, value);
110  value = vnl_math_min(1.0, value);
111  return value;
112  }
113 
118  {
119  RealType d = static_cast< RealType >( m_MaximumRGBComponentValue -
121  const RGBComponentType rescaled = static_cast< RGBComponentType >(
122  d * v ) + this->m_MinimumRGBComponentValue;
124 
125  return rescaled;
126  }
127 
128  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE
129  {
130  Superclass::PrintSelf(os, indent);
131 
132  os << indent << "Minimum RGB Component Value: "
133  << static_cast< typename NumericTraits< RGBComponentType >::PrintType >(
134  this->GetMinimumRGBComponentValue() ) << std::endl;
135  os << indent << "Maximum RGB Component Value: "
136  << static_cast< typename NumericTraits< RGBComponentType >::PrintType >(
137  this->GetMaximumRGBComponentValue() ) << std::endl;
138  os << indent << "Minimum Input Value: "
139  << static_cast< typename NumericTraits< ScalarType >::PrintType >(
140  this->GetMinimumInputValue() ) << std::endl;
141  os << indent << "Maximum Input Value: "
142  << static_cast< typename NumericTraits< ScalarType >::PrintType >(
143  this->GetMaximumInputValue() ) << std::endl;
144  }
145 
146 private:
147  ColormapFunction(const Self &); //purposely not implemented
148  void operator=(const Self &); //purposely not implemented
149 
152 
155 };
156 } // end namespace functor
157 } // end namespace itk
158 
159 #endif
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
virtual RGBComponentType GetMinimumRGBComponentValue() const
void operator=(const Self &)
virtual RGBComponentType GetMaximumRGBComponentValue() const
virtual ScalarType GetMinimumInputValue() const
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
virtual bool operator!=(const ColormapFunction &) const
static T min(const T &)
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.
RGBComponentType RescaleRGBComponentValue(RealType v) const
NumericTraits< ScalarType >::RealType RealType
static T max(const T &)
SmartPointer< const Self > ConstPointer
Control indentation during Print() invocation.
Definition: itkIndent.h:49
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:57
RealType RescaleInputValue(ScalarType v) const