ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsCovariantVectorPixel.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 __itkNumericTraitsCovariantVectorPixel_h
00019 #define __itkNumericTraitsCovariantVectorPixel_h
00020 
00021 #include "itkNumericTraits.h"
00022 #include "itkCovariantVector.h"
00023 
00024 namespace itk
00025 {
00043 template< typename T, unsigned int D >
00044 class NumericTraits< CovariantVector< 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 CovariantVector< T, D > Self;
00059 
00061   typedef CovariantVector< ElementAbsType, D > AbsType;
00062 
00064   typedef CovariantVector< ElementAccumulateType, D > AccumulateType;
00065 
00068   typedef CovariantVector< ElementFloatType, D > FloatType;
00069 
00071   typedef CovariantVector< ElementPrintType, D > PrintType;
00072 
00074   typedef CovariantVector< 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(CovariantVector< T, D > & m, const unsigned int s)
00141   {
00142     if ( s != D )
00143       {
00144       itkGenericExceptionMacro(<< "Cannot set the size of a CovariantVector of length "
00145                                << D << " to " << s);
00146       }
00147     m.Fill(NumericTraits< T >::Zero);
00148   }
00150 
00152   static unsigned int GetLength(const CovariantVector< 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 } // end namespace itk
00184 
00185 #endif // __itkNumericTraitsCovariantVectorPixel_h
00186