ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsVariableLengthVectorPixel.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 __itkNumericTraitsVariableLengthVectorPixel_h
00019 #define __itkNumericTraitsVariableLengthVectorPixel_h
00020 
00021 #include "itkVariableLengthVector.h"
00022 
00023 // This work is part of the National Alliance for Medical Image Computing
00024 // (NAMIC), funded by the National Institutes of Health through the NIH Roadmap
00025 // for Medical Research, Grant U54 EB005149.
00026 
00027 namespace itk
00028 {
00053 template< typename T >
00054 class NumericTraits< VariableLengthVector< T > >
00055 {
00056 public:
00057 
00058   typedef typename NumericTraits< T >::AbsType        ElementAbsType;
00059   typedef typename NumericTraits< T >::AccumulateType ElementAccumulateType;
00060   typedef typename NumericTraits< T >::FloatType      ElementFloatType;
00061   typedef typename NumericTraits< T >::PrintType      ElementPrintType;
00062   typedef typename NumericTraits< T >::RealType       ElementRealType;
00063 
00065   typedef T ValueType;
00066 
00067   typedef VariableLengthVector< T > Self;
00068 
00070   typedef VariableLengthVector< ElementAbsType > AbsType;
00071 
00073   typedef VariableLengthVector< ElementAccumulateType > AccumulateType;
00074 
00077   typedef VariableLengthVector< ElementFloatType > FloatType;
00078 
00080   typedef VariableLengthVector< ElementPrintType > PrintType;
00081 
00083   typedef VariableLengthVector< ElementRealType > RealType;
00084 
00086   typedef ElementRealType ScalarRealType;
00087 
00089   typedef Self MeasurementVectorType;
00090 
00096   static const Self max(const Self & a)
00097   {
00098     Self b( a.Size() );
00099 
00100     b.Fill( NumericTraits< T >::max() );
00101     return b;
00102   }
00103 
00104   static const Self min(const Self & a)
00105   {
00106     Self b( a.Size() );
00107 
00108     b.Fill( NumericTraits< T >::min() );
00109     return b;
00110   }
00111 
00112   static const Self ZeroValue(const Self  & a)
00113   {
00114     Self b( a.Size() );
00115 
00116     b.Fill(NumericTraits< T >::Zero);
00117     return b;
00118   }
00119 
00121   static const Self Zero(const Self  & a)
00122   {
00123     Self b( a.Size() );
00124 
00125     b.Fill(NumericTraits< T >::Zero);
00126     return b;
00127   }
00128 
00129   static const Self OneValue(const Self & a)
00130   {
00131     Self b( a.Size() );
00132 
00133     b.Fill(NumericTraits< T >::One);
00134     return b;
00135   }
00136 
00138   static const Self One(const Self & a)
00139   {
00140     Self b( a.Size() );
00141 
00142     b.Fill(NumericTraits< T >::One);
00143     return b;
00144   }
00145 
00146   static const Self NonpositiveMin(const Self & a)
00147   {
00148     Self b( a.Size() );
00149     b.Fill( NumericTraits< T >::NonpositiveMin() );
00150     return b;
00151   }
00152 
00154   static void SetLength(VariableLengthVector< T > & m, const unsigned int s)
00155   {
00156     m.SetSize(s);
00157     m.Fill(NumericTraits< T >::Zero);
00158   }
00160 
00162   static unsigned int GetLength(const VariableLengthVector< T > & m)
00163   {
00164     return m.GetSize();
00165   }
00166 
00167   static void AssignToArray( const Self & v, MeasurementVectorType & mv )
00168   {
00169     mv = v;
00170   }
00171 
00172   template<class TArray>
00173   static void AssignToArray( const Self & v, TArray & mv )
00174   {
00175     for( unsigned int i=0; i<GetLength(v); i++ )
00176       {
00177       mv[i] = v[i];
00178       }
00179   }
00180 
00181 };
00182 } // end namespace itk
00183 
00184 #endif // __itkNumericTraitsVariableLengthVector_h
00185