00001
00002 #ifndef vpdt_traits_h_
00003 #define vpdt_traits_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <vnl/vnl_vector.h>
00022 #include <vnl/vnl_matrix.h>
00023 #include <vnl/vnl_vector_fixed.h>
00024 #include <vnl/vnl_matrix_fixed.h>
00025 #include <vpdl/vpdt/vpdt_eigen_sym_matrix.h>
00026 #include <vcl_cassert.h>
00027
00028
00029
00030
00031
00032 template <class T>
00033 inline unsigned int vpdt_size(const vnl_vector<T>& v) { return v.size(); }
00034
00035
00036 template <class T>
00037 inline unsigned int vpdt_size(const vnl_matrix<T>& m)
00038 {
00039 assert(m.cols() == m.rows());
00040 return m.cols();
00041 }
00042
00043
00044 template <class T, unsigned int n>
00045 inline unsigned int vpdt_size(const vnl_vector_fixed<T,n>& ) { return n; }
00046
00047
00048 template <class T, unsigned int n>
00049 inline unsigned int vpdt_size(const vnl_matrix_fixed<T,n,n>& ) { return n; }
00050
00051
00052 inline unsigned int vpdt_size(float ) { return 1; }
00053 inline unsigned int vpdt_size(double ) { return 1; }
00054
00055
00056
00057
00058
00059 template <class T>
00060 inline void vpdt_set_size(vnl_vector<T>& v, unsigned int s) { v.set_size(s); }
00061
00062
00063 template <class T>
00064 inline void vpdt_set_size(vnl_matrix<T>& m, unsigned int s) { m.set_size(s,s); }
00065
00066
00067 template <class T>
00068 inline void vpdt_set_size(T& , unsigned int ) {}
00069
00070
00071
00072
00073
00074 template <class T>
00075 inline void vpdt_fill(vnl_vector<T>& v, const T& val) { v.fill(val); }
00076
00077
00078 template <class T>
00079 inline void vpdt_fill(vnl_matrix<T>& m, const T& val) { m.fill(val); }
00080
00081
00082 template <class T, unsigned int n>
00083 inline void vpdt_fill(vnl_vector_fixed<T,n>& v, const T& val) { v.fill(val); }
00084
00085
00086 template <class T, unsigned int n>
00087 inline void vpdt_fill(vnl_matrix_fixed<T,n,n>& m, const T& val) { m.fill(val); }
00088
00089
00090 template <class T>
00091 inline void vpdt_fill(T& v, const T& val) { v = val; }
00092
00093
00094
00095
00096
00097 template <class T>
00098 inline T& vpdt_index(vnl_vector<T>& v, unsigned int i) { assert(i < v.size()); return v[i]; }
00099
00100 template <class T>
00101 inline const T& vpdt_index(const vnl_vector<T>& v, unsigned int i) { assert(i < v.size()); return v[i]; }
00102
00103
00104 template <class T, unsigned int n>
00105 inline T& vpdt_index(vnl_vector_fixed<T,n>& v, unsigned int i) { assert(i < n); return v[i]; }
00106
00107 template <class T, unsigned int n>
00108 inline const T& vpdt_index(const vnl_vector_fixed<T,n>& v, unsigned int i) { assert(i < n); return v[i]; }
00109
00110
00111 template <class T>
00112 inline T& vpdt_index(T& v, unsigned int ) { return v; }
00113
00114 template <class T>
00115 inline const T& vpdt_index(const T& v, unsigned int ) { return v; }
00116
00117
00118
00119
00120
00121 template <class T>
00122 inline T& vpdt_index(vnl_matrix<T>& v, unsigned int i, unsigned int j) { assert(i < v.rows() && j < v.columns()); return v(i,j); }
00123
00124 template <class T>
00125 inline const T& vpdt_index(const vnl_matrix<T>& v, unsigned int i, unsigned int j) { assert(i < v.rows() && j < v.columns()); return v(i,j); }
00126
00127
00128 template <class T, unsigned int n>
00129 inline T& vpdt_index(vnl_matrix_fixed<T,n,n>& v, unsigned int i, unsigned int j) { assert(i < n && j < n); return v(i,j); }
00130
00131 template <class T, unsigned int n>
00132 inline const T& vpdt_index(const vnl_matrix_fixed<T,n,n>& v, unsigned int i, unsigned int j) { assert(i < n && j < n); return v(i,j); }
00133
00134
00135 template <class T>
00136 inline T& vpdt_index(T& v, unsigned int , unsigned int ) { return v; }
00137
00138 template <class T>
00139 inline const T& vpdt_index(const T& v, unsigned int , unsigned int ) { return v; }
00140
00141
00142
00143
00144
00145
00146 inline float outer_product(const float& v1, const float& v2) { return v1*v2; }
00147 inline double outer_product(const double& v1, const double& v2) { return v1*v2; }
00148
00149
00150 #endif // vpdt_traits_h_