00001 #include <TooN/TooN.h> 00002 using namespace TooN; 00003 using namespace std; 00004 00005 template<int R, int C, class B> void statictest(Matrix<R,C,double,B> m) 00006 { 00007 for(int i=0; i < 12; i++) 00008 (&m[0][0])[i] = i; 00009 00010 cout << m << endl; 00011 00012 cout << "Accessing rows as vectors:\n"; 00013 for(int i=0; i < 3; i++) 00014 cout << "... " << m[i] << "...\n"; 00015 cout << endl; 00016 00017 cout << "Slice, from [1,1], size [2,3]:\n"; 00018 cout << m.template slice<1,1,2,3>() << endl; 00019 00020 cout << "Accessing rows of a slice as vectors:\n"; 00021 for(int i=0; i < 2; i++) 00022 cout << "... " << m.template slice<1,1,2,3>()[i] << "...\n"; 00023 cout << endl; 00024 00025 00026 00027 cout << "Slice, of the above slice from [0,0], size [2,1]:\n"; 00028 cout << m.template slice<1,1,2,3>().template slice<0,0,2,1>() << endl; 00029 00030 cout << "Accessing rows of a slice of a slice as vectors:\n"; 00031 for(int i=0; i < 2; i++) 00032 cout << "... " << m.template slice<1,1,2,3>().template slice<0,0,2,1>()[i] << "...\n"; 00033 cout << endl; 00034 } 00035 00036 template<int R, int C, class B> void staticdynamictest(Matrix<R,C,double,B> m) 00037 { 00038 for(int i=0; i < 12; i++) 00039 (&m[0][0])[i] = i; 00040 00041 cout << m << endl; 00042 00043 cout << "Dynamic slice, from [1,1], size [2,3]:\n"; 00044 cout << m.slice(1,1,2,3) << endl; 00045 00046 cout << "Accessing rows of a slice as vectors:\n"; 00047 for(int i=0; i < 2; i++) 00048 cout << "... " << m.slice(1,1,2,3)[i] << "...\n"; 00049 cout << endl; 00050 00051 00052 cout << "Static slice, of the above slice from [0,0], size [2,1]:\n"; 00053 cout << m.slice(1,1,2,3).template slice<0,0,2,1>() << endl; 00054 00055 cout << "Accessing rows of a slice of a slice as vectors:\n"; 00056 for(int i=0; i < 2; i++) 00057 cout << "... " << m.slice(1,1,2,3).template slice<0,0,2,1>()[i] << "...\n"; 00058 cout << endl; 00059 00060 00061 cout << "Dynamic slice, of the above slice from [0,0], size [2,1]:\n"; 00062 cout << m.slice(1,1,2,3).slice(0,0,2,1) << endl; 00063 00064 cout << "Accessing rows of a slice of a slice as vectors:\n"; 00065 for(int i=0; i < 2; i++) 00066 cout << "... " << m.slice(1,1,2,3).slice(0,0,2,1)[i] << "...\n"; 00067 cout << endl; 00068 00069 cout << "Dynamic slice, of static version of the above slice from [0,0], size [2,1]:\n"; 00070 cout << m.template slice<1,1,2,3>().slice(0,0,2,1) << endl; 00071 00072 cout << "Accessing rows of a slice of a slice as vectors:\n"; 00073 for(int i=0; i < 2; i++) 00074 cout << "... " << m.template slice<1,1,2,3>().slice(0,0,2,1)[i] << "...\n"; 00075 cout << endl; 00076 } 00077 00078 int main() 00079 { 00080 cout << "-------------- STATIC MATRIX STATIC SLICE\n"; 00081 statictest(Matrix<3,4>()); 00082 00083 cout << "-------------- DYNAMIC MATRIX STATIC SLICE\n"; 00084 statictest(Matrix<>(3,4)); 00085 00086 cout << "-------------- STATIC MATRIX MIXED SLICE\n"; 00087 staticdynamictest(Matrix<3,4>()); 00088 00089 cout << "-------------- DYNAMIC MATRIX MIXED SLICE\n"; 00090 staticdynamictest(Matrix<>(3,4)); 00091 }