Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009
00010
00011
00012 #include "vnl_matops.h"
00013 #include <vcl_cassert.h>
00014
00015 vnl_matrix<double> vnl_matops::cat(vnl_matrix<double> const &A, vnl_matrix<double> const &B)
00016 {
00017 assert(A.rows() == B.rows());
00018
00019 vnl_matrix<double> M(A.rows(),A.columns()+B.columns());
00020 M.update(A,0,0);
00021 M.update(B,0,A.columns());
00022
00023 return M;
00024 }
00025
00026 vnl_matrix<double> vnl_matops::cat(vnl_matrix<double> const &A, vnl_vector<double> const &B)
00027 {
00028 assert(A.rows() == B.size());
00029
00030 vnl_matrix<double> M(A.rows(),A.columns()+1);
00031 M.update(A,0,0);
00032 M.set_column(A.columns(),B);
00033
00034 return M;
00035 }
00036
00037 vnl_matrix<double> vnl_matops::cat(vnl_vector<double> const &A, vnl_matrix<double> const &B)
00038 {
00039 assert(A.size() == B.rows());
00040
00041 vnl_matrix<double> M(B.rows(),B.columns()+1);
00042 M.set_column(0,A);
00043 M.update(B,0,1);
00044
00045 return M;
00046 }
00047
00048 vnl_matrix<double> vnl_matops::vcat(vnl_matrix<double> const &A, vnl_matrix<double> const &B)
00049 {
00050 assert(A.columns() == B.columns());
00051
00052 vnl_matrix<double> M(A.rows()+B.rows(),A.columns());
00053 M.update(A,0,0);
00054 M.update(B,A.rows(),0);
00055
00056 return M;
00057 }
00058
00059
00060 double vnl_matops::homg_diff(vnl_matrix<double> const& A, vnl_matrix<double> const& B)
00061 {
00062 vnl_matrix<double> ratio = element_quotient(A, B);
00063
00064 return (ratio - ratio.mean()).fro_norm();
00065 }
00066
00067 #define implement_converters(U,V) \
00068 vnl_matrix<U> make_matrix_ ## U(vnl_matrix<V> const& M) \
00069 { \
00070 unsigned m = M.rows(); \
00071 unsigned n = M.columns(); \
00072 vnl_matrix<U> ret(m, n); \
00073 for (unsigned i = 0; i < m; ++i) \
00074 for (unsigned j = 0; j < n; ++j) \
00075 ret(i,j) = static_cast<U>(M(i,j)); \
00076 return ret; \
00077 } \
00078 \
00079 vnl_vector<U> make_vector_ ## U(vnl_vector<V> const& v) \
00080 { \
00081 unsigned n = v.size(); \
00082 vnl_vector<U> ret(n); \
00083 for (unsigned i = 0; i < n; ++i) \
00084 ret[i] = static_cast<U>(v[i]); \
00085 return ret; \
00086 } \
00087
00088 implement_converters(double,float)
00089
00090 implement_converters(float,double)
00091
00092 vnl_matrix<double> vnl_matops::f2d(vnl_matrix<float> const& M)
00093 {
00094 return make_matrix_double(M);
00095 }
00096
00097 vnl_matrix<float> vnl_matops::d2f(vnl_matrix<double> const& M)
00098 {
00099 return make_matrix_float(M);
00100 }
00101
00102 vnl_vector<double> vnl_matops::f2d(vnl_vector<float> const& M)
00103 {
00104 return make_vector_double(M);
00105 }
00106
00107 vnl_vector<float> vnl_matops::d2f(vnl_vector<double> const& M)
00108 {
00109 return make_vector_float(M);
00110 }