ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsFixedArrayPixel.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 __itkNumericTraitsFixedArrayPixel_h
00019 #define __itkNumericTraitsFixedArrayPixel_h
00020 
00021 #include "itkNumericTraits.h"
00022 #include "itkFixedArray.h"
00023 
00024 namespace itk
00025 {
00043 template< typename T, unsigned int D >
00044 class NumericTraits< FixedArray< T, D > >
00045 {
00046 private:
00047 
00048   typedef  typename NumericTraits< T >::AbsType        ElementAbsType;
00049   typedef  typename NumericTraits< T >::AccumulateType ElementAccumulateType;
00050   typedef  typename NumericTraits< T >::FloatType      ElementFloatType;
00051   typedef  typename NumericTraits< T >::PrintType      ElementPrintType;
00052   typedef  typename NumericTraits< T >::RealType       ElementRealType;
00053 public:
00054 
00056   typedef T ValueType;
00057 
00058   typedef FixedArray< T, D > Self;
00059 
00061   typedef FixedArray< ElementAbsType, D > AbsType;
00062 
00064   typedef FixedArray< ElementAccumulateType, D > AccumulateType;
00065 
00068   typedef FixedArray< ElementFloatType, D > FloatType;
00069 
00071   typedef FixedArray< ElementPrintType, D > PrintType;
00072 
00074   typedef FixedArray< ElementRealType, D > RealType;
00075 
00077   typedef ElementRealType ScalarRealType;
00078 
00080   typedef Self MeasurementVectorType;
00081 
00087   static const Self max(const Self &)
00088   {
00089     return Self( NumericTraits< T >::max() );
00090   }
00091 
00092   static const Self min(const Self &)
00093   {
00094     return Self( NumericTraits< T >::min() );
00095   }
00096 
00097   static const Self max()
00098   {
00099     return Self( NumericTraits< T >::max() );
00100   }
00101 
00102   static const Self min()
00103   {
00104     return Self( NumericTraits< T >::min() );
00105   }
00106 
00107   static const Self NonpositiveMin()
00108   {
00109     return Self( NumericTraits< T >::NonpositiveMin() );
00110   }
00111 
00112   static const Self ZeroValue()
00113   {
00114     return Self( NumericTraits< T >::ZeroValue() );
00115   }
00116 
00117   static const Self OneValue()
00118   {
00119     return Self( NumericTraits< T >::OneValue() );
00120   }
00121 
00122   static const Self NonpositiveMin(const Self &)
00123   {
00124     return NonpositiveMin();
00125   }
00126 
00127   static const Self ZeroValue(const Self &)
00128   {
00129     return ZeroValue();
00130   }
00131 
00132   static const Self OneValue(const Self &)
00133   {
00134     return OneValue();
00135   }
00136 
00140   static void SetLength(FixedArray< T, D > & m, const unsigned int s)
00141   {
00142     if ( s != D )
00143       {
00144       itkGenericExceptionMacro(<< "Cannot set the size of a FixedArray of length "
00145                                << D << " to " << s);
00146       }
00147     m.Fill(NumericTraits< T >::Zero);
00148   }
00150 
00152   static unsigned int GetLength(const FixedArray< T, D > &)
00153   {
00154     return D;
00155   }
00156 
00158   static unsigned int GetLength()
00159   {
00160     return D;
00161   }
00162 
00163   static void AssignToArray( const Self & v, MeasurementVectorType & mv )
00164   {
00165     mv = v;
00166   }
00167 
00168   template<class TArray>
00169   static void AssignToArray( const Self & v, TArray & mv )
00170   {
00171     for( unsigned int i=0; i<D; i++ )
00172       {
00173       mv[i] = v[i];
00174       }
00175   }
00176 
00180   static const Self ITKCommon_EXPORT Zero;
00181   static const Self ITKCommon_EXPORT One;
00182 };
00183 
00184 // a macro to define and initialize static member variables
00185 #define itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, D)                                 \
00186   template< >                                                                                        \
00187   const GENERIC_ARRAY< T, D >  NumericTraits< GENERIC_ARRAY< T, D > >::Zero = GENERIC_ARRAY< T, D >( \
00188     NumericTraits< T >::Zero);                                                                       \
00189   template< >                                                                                        \
00190   const GENERIC_ARRAY< T, D >  NumericTraits< GENERIC_ARRAY< T, D > >::One = GENERIC_ARRAY< T, D >(  \
00191     NumericTraits< T >::One);
00192 
00193 //
00194 // List here the array dimension specializations of these static
00195 // Traits:
00196 //
00197 #define itkStaticNumericTraitsGenericArrayDimensionsMacro(GENERIC_ARRAY, T) \
00198   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 1);             \
00199   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 2);             \
00200   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 3);             \
00201   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 4);             \
00202   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 5);             \
00203   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 6);             \
00204   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 7);             \
00205   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 8);             \
00206   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 9);             \
00207   itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 10);
00208 } // end namespace itk
00209 
00210 #endif // __itkNumericTraitsFixedArrayPixel_h
00211