Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkMeasurementVectorTraits.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMeasurementVectorTraits.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/07/27 13:38:11 $
00007   Version:   $Revision: 1.3 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkMeasurementVectorTraits_h
00018 #define __itkMeasurementVectorTraits_h
00019 
00020 #include "itkMacro.h"
00021 #include "itkArray.h"
00022 #include "itkVector.h"
00023 #include "itkFixedArray.h"
00024 #include "vnl/vnl_vector_fixed.h"
00025 #include "itkPoint.h"
00026 #include "itkRGBPixel.h"
00027 #include "itkMatrix.h"
00028 #include "itkVariableSizeMatrix.h"
00029 #include "itkNumericTraits.h"
00030 #include "itkSize.h"
00031 #include <vector>
00032 
00033 
00034 namespace itk
00035 {
00036 
00043 class MeasurementVectorTraits {
00044 public:
00045 
00046   typedef unsigned int MeasurementVectorLength;
00047   
00048   template<class TValueType, unsigned int TLength>
00049   static void SetLength( FixedArray< TValueType, TLength > &m, const unsigned int s )
00050     {
00051     if( s != TLength )
00052       {
00053       itkGenericExceptionMacro( << "Cannot set the size of a FixedArray of length " 
00054           << TLength << " to " << s );
00055       }
00056     m.Fill( NumericTraits< TValueType >::Zero );
00057     }
00058   
00059   template<class TValueType, unsigned int TLength>
00060   static void SetLength( FixedArray< TValueType, TLength > *m, const unsigned int s )
00061     {
00062     if( s != TLength )
00063       {
00064       itkGenericExceptionMacro( << "Cannot set the size of a FixedArray of length " 
00065           << TLength << " to " << s );
00066       }
00067     m->Fill( NumericTraits< TValueType >::Zero );
00068     }
00069   
00070   template< class TValueType >
00071   static void SetLength( Array< TValueType > & m, const unsigned int s )
00072     {
00073     m.SetSize( s );
00074     m.Fill( NumericTraits< TValueType >::Zero );
00075     }
00076   
00077   template< class TValueType >
00078   static void SetLength( Array< TValueType > * m, const unsigned int s )
00079     {
00080     m->SetSize( s );
00081     m->Fill( NumericTraits< TValueType >::Zero );
00082     }
00083 
00084   template< class TValueType >
00085   static void SetLength( std::vector< TValueType > & m, const unsigned int s )
00086     {
00087     m.resize( s );
00088     }
00089   
00090   template< class TValueType >
00091   static void SetLength( std::vector< TValueType > * m, const unsigned int s )
00092     {
00093     m->resize( s );
00094     }
00095 
00096 
00097   template< class TValueType, unsigned int TLength > 
00098   static MeasurementVectorLength 
00099                GetLength( const FixedArray< TValueType, TLength > &)
00100     { return TLength; }
00101   
00102   template< class TValueType, unsigned int TLength > 
00103   static MeasurementVectorLength 
00104                GetLength( const FixedArray< TValueType, TLength > *)
00105     { return TLength; }
00106 
00107   template< class TValueType >
00108   static MeasurementVectorLength
00109                GetLength( const Array< TValueType > &m )
00110     {return m.GetSize(); }
00111   
00112   template< class TValueType >
00113   static MeasurementVectorLength
00114                GetLength( const Array< TValueType > *m )
00115     {return m->GetSize(); }
00116 
00117   template< class TValueType >
00118   static MeasurementVectorLength
00119                GetLength( const std::vector< TValueType > &m )
00120     {return m.size(); }
00121   
00122   template< class TValueType >
00123   static MeasurementVectorLength
00124                GetLength( const std::vector< TValueType > *m )
00125     {return m->size(); }
00126 
00127 
00128   template< class TValueType1, unsigned int TLength, class TValueType2 >
00129   static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > &, 
00130                       const Array< TValueType2 > &b, const char *errMsg="Length Mismatch")
00131     {
00132     if( b.Size() == 0 )
00133       {
00134       return TLength;
00135       }
00136     if( b.Size() != 0 )
00137       {
00138       if (b.Size() != TLength)
00139         {
00140         itkGenericExceptionMacro( << errMsg );
00141         return 0;
00142         }
00143       }
00144     return 0;
00145     }
00146 
00147   template< class TValueType1, unsigned int TLength, class TValueType2 >
00148   static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > *, 
00149                       const Array< TValueType2 > *b, const char *errMsg="Length Mismatch")
00150     {
00151     if( b->Size() == 0 )
00152       {
00153       return TLength;
00154       }
00155     else if (b->Size() != TLength)
00156       {
00157       itkGenericExceptionMacro( << errMsg );
00158       return 0;
00159       }
00160     return 0;
00161     }
00162 
00163   template< class TValueType1, unsigned int TLength>
00164   static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > &, 
00165                 const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00166     {
00167     if( l == 0 )
00168       {
00169       return TLength;
00170       }
00171     else if( l != TLength )
00172       {
00173       itkGenericExceptionMacro( << errMsg );
00174       return 0;
00175       }
00176     return 0;
00177     }
00178 
00179   template< class TValueType1, unsigned int TLength>
00180   static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > *, 
00181                const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00182     {
00183     if( l == 0 )
00184       {
00185       return TLength;
00186       }
00187     else if( l != TLength )
00188       {
00189       itkGenericExceptionMacro( << errMsg );
00190       return 0;
00191       }
00192     return 0;
00193     }
00194 
00195   template< class TValueType >
00196   static MeasurementVectorLength Assert( const Array< TValueType > &a, 
00197               const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00198     {
00199     if( ((l!=0) && (a.Size()!=l)) || (a.Size()==0) )
00200       {
00201       itkGenericExceptionMacro( << errMsg );
00202       }
00203     else if( l == 0 )
00204       {
00205       return a.Size();
00206       }
00207     return 0;
00208     }
00209   
00210   template< class TValueType >
00211   static MeasurementVectorLength Assert( const Array< TValueType > *a, 
00212               const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00213     {
00214     if( ((l!=0) && (a->Size()!=l)) || (a->Size()==0) )
00215       {
00216       itkGenericExceptionMacro( << errMsg );
00217       }
00218     else if( l == 0 )
00219       {
00220       return a->Size();
00221       }
00222     return 0;
00223     }
00224    
00225   template< class TValueType >
00226   static MeasurementVectorLength Assert( const std::vector< TValueType > &a, 
00227               const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00228     {
00229     if( ((l!=0) && (a.size()!=l)) || (a.size()==0) )
00230       {
00231       itkGenericExceptionMacro( << errMsg );
00232       }
00233     else if( l == 0 )
00234       {
00235       return a.size();
00236       }
00237     return 0;
00238     }
00239   
00240   template< class TValueType >
00241   static MeasurementVectorLength Assert( const std::vector< TValueType > *a, 
00242               const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00243     {
00244     if( ((l!=0) && (a->size()!=l)) || (a->size()==0) )
00245       {
00246       itkGenericExceptionMacro( << errMsg );
00247       }
00248     else if( l == 0 )
00249       {
00250       return a->size();
00251       }
00252     return 0;
00253     }
00254  };
00255 
00256 } // namespace itk
00257 
00258 #endif  // __itkMeasurementVectorTraits_h
00259 

Generated at Tue Aug 30 16:45:16 2005 for ITK by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2000