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