ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsVectorPixel.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 __itkNumericTraitsVectorPixel_h
00019 #define __itkNumericTraitsVectorPixel_h
00020 
00021 #include "itkNumericTraits.h"
00022 #include "itkVector.h"
00023 
00024 namespace itk
00025 {
00030 template< typename T, unsigned int D >
00031 class NumericTraits< Vector< T, D > >
00032 {
00033 private:
00034 
00035   typedef  typename NumericTraits< T >::AbsType        ElementAbsType;
00036   typedef  typename NumericTraits< T >::AccumulateType ElementAccumulateType;
00037   typedef  typename NumericTraits< T >::FloatType      ElementFloatType;
00038   typedef  typename NumericTraits< T >::PrintType      ElementPrintType;
00039   typedef  typename NumericTraits< T >::RealType       ElementRealType;
00040 public:
00041 
00043   typedef T              ValueType;
00044   typedef Vector< T, D > Self;
00045 
00047   typedef Vector< ElementAbsType, D > AbsType;
00048 
00050   typedef Vector< ElementAccumulateType, D > AccumulateType;
00051 
00054   typedef Vector< ElementFloatType, D > FloatType;
00055 
00057   typedef Vector< ElementPrintType, D > PrintType;
00058 
00060   typedef Vector< ElementRealType, D > RealType;
00061 
00063   typedef ElementRealType ScalarRealType;
00064 
00066   typedef Self MeasurementVectorType;
00067 
00073   static const Self max(const Self &)
00074   {
00075     return Self( NumericTraits< T >::max() );
00076   }
00077 
00078   static const Self min(const Self &)
00079   {
00080     return Self( NumericTraits< T >::min() );
00081   }
00082 
00083   static const Self max()
00084   {
00085     return Self( NumericTraits< T >::max() );
00086   }
00087 
00088   static const Self min()
00089   {
00090     return Self( NumericTraits< T >::min() );
00091   }
00092 
00093   static const Self NonpositiveMin()
00094   {
00095     return Self( NumericTraits< T >::NonpositiveMin() );
00096   }
00097 
00098   static const Self ZeroValue()
00099   {
00100     return Self( NumericTraits< T >::ZeroValue() );
00101   }
00102 
00103   static const Self OneValue()
00104   {
00105     return Self( NumericTraits< T >::OneValue() );
00106   }
00107 
00108   static const Self NonpositiveMin(const Self &)
00109   {
00110     return NonpositiveMin();
00111   }
00112 
00113   static const Self ZeroValue(const Self &)
00114   {
00115     return ZeroValue();
00116   }
00117 
00118   static const Self OneValue(const Self &)
00119   {
00120     return OneValue();
00121   }
00122 
00126   static void SetLength(Vector< T, D > & m, const unsigned int s)
00127   {
00128     if ( s != D )
00129       {
00130       itkGenericExceptionMacro(<< "Cannot set the size of a Vector of length "
00131                                << D << " to " << s);
00132       }
00133     m.Fill(NumericTraits< T >::Zero);
00134   }
00136 
00138   static unsigned int GetLength(const Vector< T, D > &)
00139   {
00140     return D;
00141   }
00142 
00144   static unsigned int GetLength()
00145   {
00146     return D;
00147   }
00148 
00149   static void AssignToArray( const Self & v, MeasurementVectorType & mv )
00150   {
00151     mv = v;
00152   }
00153 
00154   template<class TArray>
00155   static void AssignToArray( const Self & v, TArray & mv )
00156   {
00157     for( unsigned int i=0; i<D; i++ )
00158       {
00159       mv[i] = v[i];
00160       }
00161   }
00162 
00166   static const Self ITKCommon_EXPORT Zero;
00167   static const Self ITKCommon_EXPORT One;
00168 };
00169 } // end namespace itk
00170 
00171 #endif // __itkNumericTraitsVectorPixel_h
00172