ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkColormapFunction_h 00019 #define __itkColormapFunction_h 00020 00021 #include "itkObject.h" 00022 #include "itkObjectFactory.h" 00023 #include "itkNumericTraits.h" 00024 #include "itkRGBPixel.h" 00025 00026 namespace itk 00027 { 00028 namespace Function 00029 { 00045 template< class TScalar, class TRGBPixel > 00046 class ITK_EXPORT ColormapFunction:public Object 00047 { 00048 public: 00049 00050 typedef ColormapFunction Self; 00051 typedef Object Superclass; 00052 typedef SmartPointer< Self > Pointer; 00053 typedef SmartPointer< const Self > ConstPointer; 00054 00056 itkTypeMacro(ColormapFunction, Object); 00057 00058 typedef TRGBPixel RGBPixelType; 00059 typedef typename TRGBPixel::ComponentType RGBComponentType; 00060 typedef TScalar ScalarType; 00061 typedef typename NumericTraits< ScalarType >::RealType RealType; 00062 00063 itkSetMacro(MinimumRGBComponentValue, RGBComponentType); 00064 itkGetConstMacro(MinimumRGBComponentValue, RGBComponentType); 00065 00066 itkSetMacro(MaximumRGBComponentValue, RGBComponentType); 00067 itkGetConstMacro(MaximumRGBComponentValue, RGBComponentType); 00068 00069 itkSetMacro(MinimumInputValue, ScalarType); 00070 itkGetConstMacro(MinimumInputValue, ScalarType); 00071 00072 itkSetMacro(MaximumInputValue, ScalarType); 00073 itkGetConstMacro(MaximumInputValue, ScalarType); 00074 00075 virtual bool operator!=(const ColormapFunction &) const 00076 { 00077 return false; 00078 } 00079 00080 virtual bool operator==(const ColormapFunction & other) const 00081 { 00082 return !( *this != other ); 00083 } 00084 00085 virtual RGBPixelType operator()(const ScalarType &) const = 0; 00086 00087 protected: 00088 ColormapFunction() 00089 { 00090 this->m_MinimumInputValue = NumericTraits< TScalar >::min(); 00091 this->m_MaximumInputValue = NumericTraits< TScalar >::max(); 00092 this->m_MinimumRGBComponentValue = NumericTraits< RGBComponentType >::min(); 00093 this->m_MaximumRGBComponentValue = NumericTraits< RGBComponentType >::max(); 00094 } 00095 00096 ~ColormapFunction() {} 00097 00101 RealType RescaleInputValue(ScalarType v) const 00102 { 00103 RealType d = static_cast< RealType >( this->m_MaximumInputValue - 00104 this->m_MinimumInputValue ); 00105 RealType value = ( static_cast< RealType >( v ) - 00106 static_cast< RealType >( this->m_MinimumInputValue ) ) / d; 00108 00109 value = vnl_math_max(0.0, value); 00110 value = vnl_math_min(1.0, value); 00111 return value; 00112 } 00113 00117 RGBComponentType RescaleRGBComponentValue(RealType v) const 00118 { 00119 RealType d = static_cast< RealType >( m_MaximumRGBComponentValue - 00120 m_MinimumRGBComponentValue ); 00121 const RGBComponentType rescaled = static_cast< RGBComponentType >( 00122 d * v ) + this->m_MinimumRGBComponentValue; 00124 00125 return rescaled; 00126 } 00127 00128 void PrintSelf(std::ostream & os, Indent indent) const 00129 { 00130 Superclass::PrintSelf(os, indent); 00131 00132 os << indent << "Minimum RGB Component Value: " 00133 << static_cast< typename NumericTraits< RGBComponentType >::PrintType >( 00134 this->GetMinimumRGBComponentValue() ) << std::endl; 00135 os << indent << "Maximum RGB Component Value: " 00136 << static_cast< typename NumericTraits< RGBComponentType >::PrintType >( 00137 this->GetMaximumRGBComponentValue() ) << std::endl; 00138 os << indent << "Minimum Input Value: " 00139 << static_cast< typename NumericTraits< ScalarType >::PrintType >( 00140 this->GetMinimumInputValue() ) << std::endl; 00141 os << indent << "Maximum Input Value: " 00142 << static_cast< typename NumericTraits< ScalarType >::PrintType >( 00143 this->GetMaximumInputValue() ) << std::endl; 00144 } 00145 00146 private: 00147 ColormapFunction(const Self &); //purposely not implemented 00148 void operator=(const Self &); //purposely not implemented 00149 00150 ScalarType m_MinimumInputValue; 00151 ScalarType m_MaximumInputValue; 00152 00153 RGBComponentType m_MinimumRGBComponentValue; 00154 RGBComponentType m_MaximumRGBComponentValue; 00155 }; 00156 } // end namespace functor 00157 } // end namespace itk 00158 00159 #endif 00160