ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsArrayPixel.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 __itkNumericTraitsArrayPixel_h
00019 #define __itkNumericTraitsArrayPixel_h
00020 
00021 #include "itkNumericTraits.h"
00022 #include "itkArray.h"
00023 
00024 namespace itk
00025 {
00029 template< typename T >
00030 class NumericTraits< Array< T > >
00031 {
00032 private:
00033 
00034   typedef  typename NumericTraits< T >::AbsType        ElementAbsType;
00035   typedef  typename NumericTraits< T >::AccumulateType ElementAccumulateType;
00036   typedef  typename NumericTraits< T >::FloatType      ElementFloatType;
00037   typedef  typename NumericTraits< T >::PrintType      ElementPrintType;
00038   typedef  typename NumericTraits< T >::RealType       ElementRealType;
00039 public:
00040 
00042   typedef T              ValueType;
00043   typedef Array< T >     Self;
00044 
00046   typedef Array< ElementAbsType > AbsType;
00047 
00049   typedef Array< ElementAccumulateType > AccumulateType;
00050 
00053   typedef Array< ElementFloatType > FloatType;
00054 
00056   typedef Array< ElementPrintType > PrintType;
00057 
00059   typedef Array< ElementRealType > RealType;
00060 
00062   typedef ElementRealType ScalarRealType;
00063 
00065   typedef Self MeasurementVectorType;
00066 
00072   static const Self max(const Self & a)
00073   {
00074     Self b( a.Size() );
00075 
00076     b.Fill( NumericTraits< T >::max() );
00077     return b;
00078   }
00079 
00080   static const Self min(const Self & a)
00081   {
00082     Self b( a.Size() );
00083 
00084     b.Fill( NumericTraits< T >::min() );
00085     return b;
00086   }
00087 
00088   static const Self ZeroValue(const Self  & a)
00089   {
00090     Self b( a.Size() );
00091 
00092     b.Fill(NumericTraits< T >::Zero);
00093     return b;
00094   }
00095 
00097   static const Self Zero(const Self  & a)
00098   {
00099     Self b( a.Size() );
00100 
00101     b.Fill(NumericTraits< T >::Zero);
00102     return b;
00103   }
00104 
00105   static const Self OneValue(const Self & a)
00106   {
00107     Self b( a.Size() );
00108 
00109     b.Fill(NumericTraits< T >::One);
00110     return b;
00111   }
00112 
00114   static const Self One(const Self & a)
00115   {
00116     Self b( a.Size() );
00117 
00118     b.Fill(NumericTraits< T >::One);
00119     return b;
00120   }
00121 
00122   static const Self NonpositiveMin(const Self & a)
00123   {
00124     Self b( a.Size() );
00125     b.Fill( NumericTraits< T >::NonpositiveMin() );
00126     return b;
00127   }
00128 
00130   static void SetLength(Array< T > & m, const unsigned int s)
00131   {
00132     m.SetSize(s);
00133     m.Fill(NumericTraits< T >::Zero);
00134   }
00136 
00138   static unsigned int GetLength(const Array< T > & m)
00139   {
00140     return m.GetSize();
00141   }
00142 
00143   static void AssignToArray( const Self & v, MeasurementVectorType & mv )
00144   {
00145     mv = v;
00146   }
00147 
00148   template<class TArray>
00149   static void AssignToArray( const Self & v, TArray & mv )
00150   {
00151     for( unsigned int i=0; i<GetLength(v); i++ )
00152       {
00153       mv[i] = v[i];
00154       }
00155   }
00156 
00157 };
00158 } // end namespace itk
00159 
00160 #endif // __itkNumericTraitsArrayPixel_h
00161