ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsStdVector.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 
00019 #ifndef __itkNumericTraitsStdVector_h
00020 #define __itkNumericTraitsStdVector_h
00021 
00022 #include "itkNumericTraits.h"
00023 #include <vector>
00024 
00025 // This work is part of the National Alliance for Medical Image Computing
00026 // (NAMIC), funded by the National Institutes of Health through the NIH Roadmap
00027 // for Medical Research, Grant U54 EB005149.
00028 
00029 namespace itk
00030 {
00055 template< typename T >
00056 class NumericTraits< std::vector< T > >
00057 {
00058 public:
00059 
00060   typedef typename NumericTraits< T >::AbsType        ElementAbsType;
00061   typedef typename NumericTraits< T >::AccumulateType ElementAccumulateType;
00062   typedef typename NumericTraits< T >::FloatType      ElementFloatType;
00063   typedef typename NumericTraits< T >::PrintType      ElementPrintType;
00064   typedef typename NumericTraits< T >::RealType       ElementRealType;
00065 
00067   typedef T ValueType;
00068 
00069   typedef std::vector< T > Self;
00070 
00072   typedef std::vector< ElementAbsType > AbsType;
00073 
00075   typedef std::vector< ElementAccumulateType > AccumulateType;
00076 
00079   typedef std::vector< ElementFloatType > FloatType;
00080 
00081   // TODO: this won't really print well, at least not without defining an operator
00082   // to push to a stream.
00084   typedef std::vector< ElementPrintType > PrintType;
00085 
00087   typedef std::vector< ElementRealType > RealType;
00088 
00090   typedef ElementRealType ScalarRealType;
00091 
00093   typedef Self MeasurementVectorType;
00094 
00100   static const Self max(const Self & a)
00101   {
00102     Self b( a.Size(), NumericTraits< T >::max() );
00103     return b;
00104   }
00106 
00107   static const Self min(const Self & a)
00108   {
00109     Self b( a.Size(), NumericTraits< T >::min() );
00110     return b;
00111   }
00112 
00113   static const Self ZeroValue(const Self  & a)
00114   {
00115     Self b( a.Size(), NumericTraits< T >::Zero );
00116     return b;
00117   }
00118 
00119   static const Self OneValue(const Self & a)
00120   {
00121     Self b( a.Size(), NumericTraits< T >::One );
00122     return b;
00123   }
00124 
00125   static const Self NonpositiveMin(const Self & a)
00126   {
00127     Self b( a.Size(), NumericTraits< T >::NonpositiveMin() );
00128     return b;
00129   }
00130 
00132   static void SetLength(std::vector< T > & m, const unsigned int s)
00133   {
00134     m.resize(s);
00135   }
00136 
00138   static unsigned int GetLength(const std::vector< T > & m)
00139   {
00140     return m.size();
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 // __itkNumericTraitsStdVector_h
00161