ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsRGBPixel.h
Go to the documentation of this file.
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 __itkNumericTraitsRGBPixel_h
00019 #define __itkNumericTraitsRGBPixel_h
00020 
00021 #include "itkNumericTraits.h"
00022 #include "itkRGBPixel.h"
00023 
00024 namespace itk
00025 {
00042 template< typename T >
00043 class NumericTraits< RGBPixel< T > >
00044 {
00045 private:
00046 
00047   typedef typename NumericTraits< T >::AbsType        ElementAbsType;
00048   typedef typename NumericTraits< T >::AccumulateType ElementAccumulateType;
00049   typedef typename NumericTraits< T >::FloatType      ElementFloatType;
00050   typedef typename NumericTraits< T >::PrintType      ElementPrintType;
00051   typedef typename NumericTraits< T >::RealType       ElementRealType;
00052 public:
00053 
00055   typedef T ValueType;
00056 
00057   typedef RGBPixel< T > Self;
00058 
00060   typedef RGBPixel< ElementAbsType > AbsType;
00061 
00063   typedef RGBPixel< ElementAccumulateType > AccumulateType;
00064 
00067   typedef RGBPixel< ElementFloatType > FloatType;
00068 
00070   typedef RGBPixel< ElementPrintType > PrintType;
00071 
00073   typedef RGBPixel< ElementRealType > RealType;
00074 
00076   typedef ElementRealType ScalarRealType;
00077 
00079   typedef Self MeasurementVectorType;
00080 
00086   static const Self max(const Self &)
00087   {
00088     return Self( NumericTraits< T >::max() );
00089   }
00090 
00091   static const Self min(const Self &)
00092   {
00093     return Self( NumericTraits< T >::min() );
00094   }
00095 
00096   static const Self max()
00097   {
00098     return Self( NumericTraits< T >::max() );
00099   }
00100 
00101   static const Self min()
00102   {
00103     return Self( NumericTraits< T >::min() );
00104   }
00105 
00106   static const Self NonpositiveMin()
00107   {
00108     return Self( NumericTraits< ValueType >::NonpositiveMin() );
00109   }
00110 
00111   static const Self ZeroValue()
00112   {
00113     return Self(NumericTraits< T >::Zero);
00114   }
00115 
00116   static const Self OneValue()
00117   {
00118     return Self(NumericTraits< T >::One);
00119   }
00120 
00121   static const Self NonpositiveMin(const Self &)
00122   {
00123     return NonpositiveMin();
00124   }
00125 
00126   static const Self ZeroValue(const Self &)
00127   {
00128     return ZeroValue();
00129   }
00130 
00131   static const Self OneValue(const Self &)
00132   {
00133     return OneValue();
00134   }
00135 
00139   static void SetLength(RGBPixel< T > & m, const unsigned int s)
00140   {
00141     if ( s != 3 )
00142       {
00143       itkGenericExceptionMacro(<< "Cannot set the size of a RGBPixel to anything other "
00144                                "than 3.");
00145       }
00146     m.Fill(NumericTraits< T >::Zero);
00147   }
00149 
00151   static unsigned int GetLength(const RGBPixel< T > &)
00152   {
00153     return 3;
00154   }
00155 
00157   static unsigned int GetLength()
00158   {
00159     return 3;
00160   }
00161 
00162   static void AssignToArray( const Self & v, MeasurementVectorType & mv )
00163   {
00164     mv = v;
00165   }
00166 
00167   template<class TArray>
00168   static void AssignToArray( const Self & v, TArray & mv )
00169   {
00170     for( unsigned int i=0; i<3; i++ )
00171       {
00172       mv[i] = v[i];
00173       }
00174   }
00175 
00179   static const Self ITKCommon_EXPORT Zero;
00180   static const Self ITKCommon_EXPORT One;
00181 };
00182 } // end namespace itk
00183 
00184 #endif // __itkNumericTraitsRGBPixel_h
00185