00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkMeasurementVectorTraits_h
00018 #define __itkMeasurementVectorTraits_h
00019
00020 #include "itkMacro.h"
00021 #include "itkArray.h"
00022 #include "itkVariableLengthVector.h"
00023 #include "itkVector.h"
00024 #include "itkFixedArray.h"
00025 #include "vnl/vnl_vector_fixed.h"
00026 #include "itkPoint.h"
00027 #include "itkRGBPixel.h"
00028 #include "itkMatrix.h"
00029 #include "itkVariableSizeMatrix.h"
00030 #include "itkNumericTraits.h"
00031 #include "itkSize.h"
00032 #include <vector>
00033
00034
00035 namespace itk
00036 {
00037
00044 class MeasurementVectorTraits {
00045 public:
00046
00047 typedef unsigned int MeasurementVectorLength;
00048
00049 template<class TValueType, unsigned int TLength>
00050 static void SetLength( FixedArray< TValueType, TLength > &m, const unsigned int s )
00051 {
00052 if( s != TLength )
00053 {
00054 itkGenericExceptionMacro( << "Cannot set the size of a FixedArray of length "
00055 << TLength << " to " << s );
00056 }
00057 m.Fill( NumericTraits< TValueType >::Zero );
00058 }
00059
00060 template<class TValueType, unsigned int TLength>
00061 static void SetLength( FixedArray< TValueType, TLength > *m, const unsigned int s )
00062 {
00063 if( s != TLength )
00064 {
00065 itkGenericExceptionMacro( << "Cannot set the size of a FixedArray of length "
00066 << TLength << " to " << s );
00067 }
00068 m->Fill( NumericTraits< TValueType >::Zero );
00069 }
00070
00071 template< class TValueType >
00072 static void SetLength( Array< TValueType > & m, const unsigned int s )
00073 {
00074 m.SetSize( s );
00075 m.Fill( NumericTraits< TValueType >::Zero );
00076 }
00077
00078 template< class TValueType >
00079 static void SetLength( Array< TValueType > * m, const unsigned int s )
00080 {
00081 m->SetSize( s );
00082 m->Fill( NumericTraits< TValueType >::Zero );
00083 }
00084
00085 template< class TValueType >
00086 static void SetLength( VariableLengthVector< TValueType > & m, const unsigned int s )
00087 {
00088 m.SetSize( s );
00089 m.Fill( NumericTraits< TValueType >::Zero );
00090 }
00091
00092 template< class TValueType >
00093 static void SetLength( VariableLengthVector< TValueType > * m, const unsigned int s )
00094 {
00095 m->SetSize( s );
00096 m->Fill( NumericTraits< TValueType >::Zero );
00097 }
00098
00099 template< class TValueType >
00100 static void SetLength( std::vector< TValueType > & m, const unsigned int s )
00101 {
00102 m.resize( s );
00103 }
00104
00105 template< class TValueType >
00106 static void SetLength( std::vector< TValueType > * m, const unsigned int s )
00107 {
00108 m->resize( s );
00109 }
00110
00111
00112 template< class TValueType, unsigned int TLength >
00113 static MeasurementVectorLength
00114 GetLength( const FixedArray< TValueType, TLength > &)
00115 { return TLength; }
00116
00117 template< class TValueType, unsigned int TLength >
00118 static MeasurementVectorLength
00119 GetLength( const FixedArray< TValueType, TLength > *)
00120 { return TLength; }
00121
00122 template< class TValueType >
00123 static MeasurementVectorLength
00124 GetLength( const Array< TValueType > &m )
00125 {return m.GetSize(); }
00126
00127 template< class TValueType >
00128 static MeasurementVectorLength
00129 GetLength( const Array< TValueType > *m )
00130 {return m->GetSize(); }
00131
00132 template< class TValueType >
00133 static MeasurementVectorLength
00134 GetLength( const VariableLengthVector< TValueType > &m )
00135 {return m.GetSize(); }
00136
00137 template< class TValueType >
00138 static MeasurementVectorLength
00139 GetLength( const VariableLengthVector< TValueType > *m )
00140 {return m->GetSize(); }
00141
00142 template< class TValueType >
00143 static MeasurementVectorLength
00144 GetLength( const std::vector< TValueType > &m )
00145 {return m.size(); }
00146
00147 template< class TValueType >
00148 static MeasurementVectorLength
00149 GetLength( const std::vector< TValueType > *m )
00150 {return m->size(); }
00151
00152
00153 template< class TValueType1, unsigned int TLength, class TValueType2 >
00154 static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > &,
00155 const Array< TValueType2 > &b, const char *errMsg="Length Mismatch")
00156 {
00157 if( b.Size() == 0 )
00158 {
00159 return TLength;
00160 }
00161 if( b.Size() != 0 )
00162 {
00163 if (b.Size() != TLength)
00164 {
00165 itkGenericExceptionMacro( << errMsg );
00166 return 0;
00167 }
00168 }
00169 return 0;
00170 }
00171
00172 template< class TValueType1, unsigned int TLength, class TValueType2 >
00173 static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > *,
00174 const Array< TValueType2 > *b, const char *errMsg="Length Mismatch")
00175 {
00176 if( b->Size() == 0 )
00177 {
00178 return TLength;
00179 }
00180 else if (b->Size() != TLength)
00181 {
00182 itkGenericExceptionMacro( << errMsg );
00183 return 0;
00184 }
00185 return 0;
00186 }
00187
00188 template< class TValueType1, unsigned int TLength, class TValueType2 >
00189 static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > &,
00190 const VariableLengthVector< TValueType2 > &b, const char *errMsg="Length Mismatch")
00191 {
00192 if( b.Size() == 0 )
00193 {
00194 return TLength;
00195 }
00196 if( b.Size() != 0 )
00197 {
00198 if (b.Size() != TLength)
00199 {
00200 itkGenericExceptionMacro( << errMsg );
00201 return 0;
00202 }
00203 }
00204 return 0;
00205 }
00206
00207 template< class TValueType1, unsigned int TLength, class TValueType2 >
00208 static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > *,
00209 const VariableLengthVector< TValueType2 > *b, const char *errMsg="Length Mismatch")
00210 {
00211 if( b->Size() == 0 )
00212 {
00213 return TLength;
00214 }
00215 else if (b->Size() != TLength)
00216 {
00217 itkGenericExceptionMacro( << errMsg );
00218 return 0;
00219 }
00220 return 0;
00221 }
00222
00223 template< class TValueType1, unsigned int TLength>
00224 static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > &,
00225 const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00226 {
00227 if( l == 0 )
00228 {
00229 return TLength;
00230 }
00231 else if( l != TLength )
00232 {
00233 itkGenericExceptionMacro( << errMsg );
00234 return 0;
00235 }
00236 return 0;
00237 }
00238
00239 template< class TValueType1, unsigned int TLength>
00240 static MeasurementVectorLength Assert( const FixedArray< TValueType1, TLength > *,
00241 const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00242 {
00243 if( l == 0 )
00244 {
00245 return TLength;
00246 }
00247 else if( l != TLength )
00248 {
00249 itkGenericExceptionMacro( << errMsg );
00250 return 0;
00251 }
00252 return 0;
00253 }
00254
00255 template< class TValueType >
00256 static MeasurementVectorLength Assert( const Array< TValueType > &a,
00257 const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00258 {
00259 if( ((l!=0) && (a.Size()!=l)) || (a.Size()==0) )
00260 {
00261 itkGenericExceptionMacro( << errMsg );
00262 }
00263 else if( l == 0 )
00264 {
00265 return a.Size();
00266 }
00267 return 0;
00268 }
00269
00270 template< class TValueType >
00271 static MeasurementVectorLength Assert( const Array< TValueType > *a,
00272 const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00273 {
00274 if( ((l!=0) && (a->Size()!=l)) || (a->Size()==0) )
00275 {
00276 itkGenericExceptionMacro( << errMsg );
00277 }
00278 else if( l == 0 )
00279 {
00280 return a->Size();
00281 }
00282 return 0;
00283 }
00284
00285 template< class TValueType >
00286 static MeasurementVectorLength Assert( const VariableLengthVector< TValueType > &a,
00287 const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00288 {
00289 if( ((l!=0) && (a.Size()!=l)) || (a.Size()==0) )
00290 {
00291 itkGenericExceptionMacro( << errMsg );
00292 }
00293 else if( l == 0 )
00294 {
00295 return a.Size();
00296 }
00297 return 0;
00298 }
00299
00300 template< class TValueType >
00301 static MeasurementVectorLength Assert( const VariableLengthVector< TValueType > *a,
00302 const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00303 {
00304 if( ((l!=0) && (a->Size()!=l)) || (a->Size()==0) )
00305 {
00306 itkGenericExceptionMacro( << errMsg );
00307 }
00308 else if( l == 0 )
00309 {
00310 return a->Size();
00311 }
00312 return 0;
00313 }
00314 template< class TValueType >
00315 static MeasurementVectorLength Assert( const std::vector< TValueType > &a,
00316 const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00317 {
00318 if( ((l!=0) && (a.size()!=l)) || (a.size()==0) )
00319 {
00320 itkGenericExceptionMacro( << errMsg );
00321 }
00322 else if( l == 0 )
00323 {
00324 return a.size();
00325 }
00326 return 0;
00327 }
00328
00329 template< class TValueType >
00330 static MeasurementVectorLength Assert( const std::vector< TValueType > *a,
00331 const MeasurementVectorLength l, const char *errMsg="Length Mismatch")
00332 {
00333 if( ((l!=0) && (a->size()!=l)) || (a->size()==0) )
00334 {
00335 itkGenericExceptionMacro( << errMsg );
00336 }
00337 else if( l == 0 )
00338 {
00339 return a->size();
00340 }
00341 return 0;
00342 }
00343 };
00344
00345 }
00346
00347 #endif // __itkMeasurementVectorTraits_h
00348
00349