ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsTensorPixel.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 __itkNumericTraitsTensorPixel_h
00019 #define __itkNumericTraitsTensorPixel_h
00020 
00021 #include "itkNumericTraits.h"
00022 #include "itkSymmetricSecondRankTensor.h"
00023 
00024 namespace itk
00025 {
00043 template< typename T, unsigned int D >
00044 class NumericTraits< SymmetricSecondRankTensor< 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 SymmetricSecondRankTensor< T, D > Self;
00059 
00061   typedef SymmetricSecondRankTensor< ElementAbsType, D > AbsType;
00062 
00064   typedef SymmetricSecondRankTensor< ElementAccumulateType, D > AccumulateType;
00065 
00068   typedef SymmetricSecondRankTensor< ElementFloatType, D > FloatType;
00069 
00071   typedef SymmetricSecondRankTensor< ElementPrintType, D > PrintType;
00072 
00074   typedef SymmetricSecondRankTensor< 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 
00141   static void SetLength(SymmetricSecondRankTensor< T, D > & m, const unsigned int s)
00142   {
00143     if ( s != D *( D + 1 ) / 2 )
00144       {
00145       itkGenericExceptionMacro(<< "Cannot set the size of a SymmetricSecondRankTensor "
00146                                "of dimension " << D << " ( = size of "
00147                                << D *( D + 1 ) / 2 << ") to " << s);
00148       }
00149     m.Fill(NumericTraits< T >::Zero);
00150   }
00152 
00154   static unsigned int GetLength(const SymmetricSecondRankTensor< T, D > &)
00155   {
00156     return GetLength();
00157   }
00158 
00160   static unsigned int GetLength()
00161   {
00162     return D *( D + 1 ) / 2;
00163   }
00164 
00165   static void AssignToArray( const Self & v, MeasurementVectorType & mv )
00166   {
00167     mv = v;
00168   }
00169 
00170   template<class TArray>
00171   static void AssignToArray( const Self & v, TArray & mv )
00172   {
00173     for( unsigned int i=0; i<GetLength(); i++ )
00174       {
00175       mv[i] = v[i];
00176       }
00177   }
00178 
00182   static const Self ITKCommon_EXPORT Zero;
00183   static const Self ITKCommon_EXPORT One;
00184 };
00185 } // end namespace itk
00186 
00187 #endif // __itkNumericTraitsTensorPixel_h
00188